You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Part of the Agent migration epic #152 (platform hardening). Owner: Jack.
Goal
Make agent structured-output robust: systematic retry-on-validation and defensive handling so malformed/partial model output and provider schema rejections never surface as raw 500s.
Why
The orchestrator-schema-complexity attempt showed Gemini's structured-output API rejects complex schemas before the model even runs — outputs must stay small/flat. That rule is folklore today, not enforced.
The audit's agents/LLM pass flagged JSON-mode parsing that can crash on malformed output.
Scope
Retry-on-validation: set output_retries (and use ModelRetry) on the agents so a transient invalid output retries instead of failing the request.
Codify the output-type rule from the attempt: keep agent output types under ~5 flat fields, prefer enums to constrained strings, no nested optional models. Add a short note in backend/agents/ (or docs/decisions/) so it isn't relearned.
Map failures to clean errors:UnexpectedModelBehavior / UsageLimitExceeded / provider schema-rejection → a typed error response (and the terminal SSE error event on streaming routes), not a raw 500. Reuse the request_id correlation.
Files
backend/agents/*.py (output types + output_retries), backend/agents/_providers.py, backend/services/gemini_service.py (JSON helpers, until retired by #151).
Acceptance
A deliberately malformed model output retries and then degrades to a typed error, not a 500 — covered by a test in backend/tests/.
Output-type guidance documented and the current agents conform.
Part of the Agent migration epic #152 (platform hardening). Owner: Jack.
Goal
Make agent structured-output robust: systematic retry-on-validation and defensive handling so malformed/partial model output and provider schema rejections never surface as raw 500s.
Why
orchestrator-schema-complexityattempt showed Gemini's structured-output API rejects complex schemas before the model even runs — outputs must stay small/flat. That rule is folklore today, not enforced.Scope
output_retries(and useModelRetry) on the agents so a transient invalid output retries instead of failing the request.backend/agents/(ordocs/decisions/) so it isn't relearned.call_gemini_jsonpaths until they migrate ([P1] Agent migration: document classify/extract step → Pydantic AI agent #143–[P2] Agent migration: remaining one-shot LLM calls (study guide, social, health) → agents/seam #147): guard against non-JSON / partial output.UnexpectedModelBehavior/UsageLimitExceeded/ provider schema-rejection → a typed error response (and the terminal SSEerrorevent on streaming routes), not a raw 500. Reuse therequest_idcorrelation.Files
backend/agents/*.py(output types +output_retries),backend/agents/_providers.py,backend/services/gemini_service.py(JSON helpers, until retired by #151).Acceptance
backend/tests/.