Skip to content

Validate LLM API response fields to prevent silent failures - #30

Merged
claude[bot] merged 1 commit into
mainfrom
improve/20260826-104939
Aug 26, 2026
Merged

Validate LLM API response fields to prevent silent failures#30
claude[bot] merged 1 commit into
mainfrom
improve/20260826-104939

Conversation

@ssevera1

Copy link
Copy Markdown
Owner

What

Add validation to check that LLM API responses contain expected fields before accessing them.

Why

Malformed or unexpected API responses can cause silent failures when required fields are missing, making debugging difficult. This adds explicit validation and clear error messages.

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Checked the diff against the stated intent: it adds a _validate_response helper and applies it to the non-streaming chat() and generate() paths, which is exactly what the title/description promise, with no unrelated changes bundled in.

The one real behavior change is that chat() now raises OllamaError instead of returning a dict without message — that's already caught at agent/core/engine.py:89 and surfaced as a user-facing "LLM Error", so it fails loudly rather than silently looping on empty content until max_turns. Streaming is correctly left unvalidated since _stream_chat builds full_response with a message key itself, the helper is mypy-safe against _request's -> dict signature, and no existing test mocks LLMClient.chat directly (they patch _call_llm).

Minor, non-blocking: the error interpolates the entire response dict via Got: {response}, which could be a large blob in the terminal — a truncated repr would read better.

@claude
claude Bot merged commit 837c061 into main Aug 26, 2026
3 checks passed
@claude
claude Bot deleted the improve/20260826-104939 branch August 26, 2026 10:51
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.

1 participant