Repository navigation
fix(llm): surface invalid structured output - #996
foma-agent wants to merge 1 commit into
Conversation
WalkthroughStructured-output parsing now validates schema relevance across Anthropic, Gemini, and OpenAI backends. Repairable truncated JSON remains supported. Unrecoverable or schema-irrelevant responses raise sanitized ChangesStructured output validation
Estimated code review effort: 4 (Complex) | ~45 minutes Sequence Diagram(s)sequenceDiagram
participant LLMBackend
participant StructuredOutputValidator
participant JSONRepair
participant Caller
LLMBackend->>StructuredOutputValidator: Validate parsed or raw response
StructuredOutputValidator-->>LLMBackend: Return valid structured output
StructuredOutputValidator->>JSONRepair: Handle decoding or validation failure
JSONRepair-->>LLMBackend: Return repaired output
JSONRepair-->>Caller: Raise StructuredOutputError when repair fails
Possibly related PRs
Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/llm/structured_output.py (1)
38-38: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winAdd Google-style docstrings to the changed functions.
src/llm/structured_output.py#L38-L38: Document repair behavior, arguments, return value, and raised errors.src/llm/structured_output.py#L114-L117: Document supported payload types and error behavior.src/llm/structured_output.py#L137-L158: Document schema relevance and empty-object detection behavior.As per coding guidelines,
In Python code, use Google-style docstrings.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/llm/structured_output.py` at line 38, The changed functions in src/llm/structured_output.py at lines 38-38, 114-117, and 137-158 require Google-style docstrings: document the first function’s JSON repair behavior, arguments, return value, and raised errors; document the second function’s supported payload types and error behavior; and document the third function’s schema relevance and empty-object detection behavior.Source: Coding guidelines
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@src/llm/structured_output.py`:
- Line 38: The changed functions in src/llm/structured_output.py at lines 38-38,
114-117, and 137-158 require Google-style docstrings: document the first
function’s JSON repair behavior, arguments, return value, and raised errors;
document the second function’s supported payload types and error behavior; and
document the third function’s schema relevance and empty-object detection
behavior.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: e6462f48-668b-4ff1-b47b-9bb4afe38bdb
📒 Files selected for processing (9)
src/llm/backends/anthropic.pysrc/llm/backends/gemini.pysrc/llm/backends/openai.pysrc/llm/structured_output.pytests/llm/test_backends/test_anthropic.pytests/llm/test_backends/test_gemini.pytests/llm/test_backends/test_openai.pytests/llm/test_structured_output.pytests/utils/test_length_finish_reason.py
Summary
StructuredOutputErrorwhenPromptRepresentationJSON is malformed or has no recognized schema fields instead of silently returning an empty representationVerification
uv run pytest -q— 1818 passed, 25 skippeduv run basedpyright— 0 errors, 0 warningsCloses #993
Summary by CodeRabbit
Bug Fixes
Tests