Skip to content

Bug: Unhandled LLM RuntimeError crashes /api/chat with raw 500 if Ollama/Groq goes down #17

Description

@anushagarg6

Description

If Ollama crashes or Groq rate-limits mid-request, ask_ollama() in backend/llm/client.py raises a RuntimeError. This exception is not caught in the /api/chat route in backend/app.py, so it propagates as an unhandled 500 Internal Server Error with a raw Python traceback.

Reproduction

  1. Start the backend
  2. Stop Ollama (pkill ollama) or exhaust Groq rate limits
  3. Send any chat message
  4. Observe: raw 500 error, no user-friendly message

Impact

Users see a confusing error with no indication of what went wrong or how to fix it. The frontend displays a generic failure with no actionable guidance.

Fix Needed

Wrap the answer_question() call in /api/chat with a try/except RuntimeError block:

try:
    result = answer_question(question, session_id, language)
except RuntimeError as e:
    raise HTTPException(status_code=503, detail=str(e))

This returns a clean 503 Service Unavailable with the specific LLM error message (e.g. "Cannot connect to Ollama. Is 'ollama serve' running?").

Files Affected

  • backend/app.py — /api/chat route

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions