Skip to content

FIX : Improves Ollama request robustness in textToJSON.main_loop#171

Open
Aryama-srivastav wants to merge 2 commits intofireform-core:mainfrom
Aryama-srivastav:169
Open

FIX : Improves Ollama request robustness in textToJSON.main_loop#171
Aryama-srivastav wants to merge 2 commits intofireform-core:mainfrom
Aryama-srivastav:169

Conversation

@Aryama-srivastav
Copy link

Description

This PR improves Ollama request robustness in textToJSON.main_loop by handling request failures explicitly instead of letting raw networking exceptions propagate.

What changed

  • Added timeout to Ollama POST requests.
  • Added request failure handling for requests.exceptions.RequestException.
  • Added explicit error handling for non-JSON responses.
  • Added response schema validation to ensure the expected "response" key exists before use.

Why

Previously, when OLLAMA_HOST was unreachable, the code surfaced raw requests/urllib3 stack traces. With this change, the backend now raises a clear, controlled RuntimeError with actionable context (target Ollama URL and failure reason), improving reliability and debugging experience.

Fixes #169

Type of change

  • Bug fix (non-breaking change which fixes an issue)

How Has This Been Tested?

  • Test A (repro path):
    Set:
    PYTHONPATH=src
    OLLAMA_HOST=http://127.0.0.1:18080 (unreachable host)
    Run:
    python -c "from backend import textToJSON; try: textToJSON('employee is John', ['Employee name']); except Exception as e: print(type(e).name); print(e)"

Result:
RuntimeError
Message starts with Failed to reach Ollama at http://127.0.0.1:18080/api/generate: ...

  • Test B (regression intent):
    Verified that failure is now raised from application code as a controlled exception, rather than uncaught raw requests.exceptions.ConnectionError.

Test Configuration:

  • Firmware version: N/A
  • Hardware: Windows laptop (local)
  • SDK: N/A
  • Python: 3.13
  • Shell: PowerShell

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BUG : Ollama connectivity failures

1 participant