{"record":{"id":"9be80b5ce647cbe1","repo":"Zie619/n8n-workflows","slug":"assistant-error-str-e","errorCode":null,"errorMessage":"Assistant error: {str(e)}","messagePattern":"Assistant error: (.+?)","errorType":"http","errorClass":"HTTPException","httpStatus":500,"severity":"error","filePath":"src/ai_assistant.py","lineNumber":280,"sourceCode":"\n        # Generate response\n        response_text = assistant.generate_response(message.message, workflows)\n\n        # Get suggestions\n        suggestions = assistant.get_suggestions(message.message)\n\n        # Calculate confidence\n        confidence = assistant.calculate_confidence(message.message, workflows)\n\n        return AIResponse(\n            response=response_text,\n            workflows=workflows,\n            suggestions=suggestions,\n            confidence=confidence,\n        )\n\n    except Exception as e:\n        raise HTTPException(status_code=500, detail=f\"Assistant error: {str(e)}\")\n\n\n@ai_app.get(\"/chat/interface\")\nasync def chat_interface():\n    \"\"\"Get the chat interface HTML.\"\"\"\n    html_content = \"\"\"\n    <!DOCTYPE html>\n    <html lang=\"en\">\n    <head>\n        <meta charset=\"UTF-8\">\n        <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\n        <title>N8N AI Assistant</title>\n        <style>\n            * { margin: 0; padding: 0; box-sizing: border-box; }\n            body { \n                font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;\n                background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);\n                height: 100vh;","sourceCodeStart":262,"sourceCodeEnd":298,"githubUrl":"https://github.com/Zie619/n8n-workflows/blob/94007c1445d9258a7da116646b79473e7c7c3282/src/ai_assistant.py#L262-L298","documentation":"A generic 500 from the AI assistant chat endpoint (ai_app). The handler runs the assistant pipeline (response generation, suggestions, confidence calculation) and wraps any failure as 'Assistant error: {str(e)}'. Failures usually originate in the LLM/assistant backend: missing API keys, model timeouts, or malformed workflow data passed into calculate_confidence.","triggerScenarios":"POST to the AI chat endpoint with a message when the assistant's LLM provider key is missing/invalid, the model call times out or rate-limits, or the workflows list handed to calculate_confidence contains unexpected shapes raising inside the try block.","commonSituations":"OPENAI/LLM API key not set in the server environment; expired quota or network egress blocked from the server; assistant library version changed its internal API after a dependency update; empty workflow index making downstream processing fail.","solutions":["Read the str(e) suffix in the 500 detail — it is the underlying assistant exception (auth error, timeout, KeyError) and points at the failing stage.","Verify required LLM/env credentials are present in the server process and that a minimal assistant call works standalone.","If the error names calculate_confidence or suggestions, re-index the workflow DB so the data shape matches what the assistant expects.","Pin/align the assistant dependency versions and retry after restart."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"import os\n\ndef assistant_config_ready() -> bool:\n    # adjust key names to the assistant backend actually used\n    return bool(os.environ.get(\"OPENAI_API_KEY\") or os.environ.get(\"ANTHROPIC_API_KEY\"))","typeGuard":null,"tryCatchPattern":"try:\n    result = client.post(\"/ai/chat\", json={\"message\": msg}).json()\nexcept HTTPError as e:\n    if e.response.status_code == 500 and \"Assistant error\" in e.response.text:\n        # LLM backends fail transiently (rate limit, timeout): one bounded retry is reasonable\n        result = client.post(\"/ai/chat\", json={\"message\": msg}).json()\n    else:\n        raise","preventionTips":["Fail fast at startup if required LLM keys are missing instead of 500ing per request.","Set client timeouts shorter than the server's so users see a clear timeout, not a hang.","Treat assistant responses as progressive enhancement; the core search must work without AI."],"tags":["http-500","llm","ai-assistant","fastapi","configuration"],"backgroundTag":null,"analyzedSha":"94007c1445d9258a7da116646b79473e7c7c3282","analyzedAt":"2026-08-15T04:10:37.591Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}