What this thread does
Do first: use run_stream_events() instead of run_stream() when you need streamed events followed by the output tool's result.
Symptom
Structured Output fails with text output + Behaviour inconsistency is the symptom title, rather than an exception message. IngLP reported that streaming with output_type=Union[str, CallAgent] returned text instead of the structured handoff, while the non-streaming run returned structured output. Other affected users were smomen, CharlieEriksen, and IgnazioDS.
Cause
With text included in the allowed output types, run_stream() commits to the first matching output. Text arriving before an output tool call can therefore end the run; the subsequent output tool is not used. This is intended behavior, as explained in the resolution PR, rather than a schema-validation failure.
Fix
1. For streamed events and a run that continues through tool execution, select run_stream_events(); iter() is the documented alternative when consuming the agent graph directly. 2. If streaming is unnecessary, use run() to obtain the output tool's result in this text-before-tool case. 3. Choose the method according to the output you need: keeping run_stream() with text as an allowed output retains first-matching-output behavior.
These choices are documented in Streamed Results at v2.73.0, the stable release published on 2026-11-24.
Fixed in
The documentation clarification is fixed in v2.66.0 (released 2026-11-04), the first carrying stable release. The rolling clai2-bleeding pre-release tag also contains the commit as checked on 2026-11-24; its original publication date does not establish when it first carried this change. PR #12279 merged on 2026-11-03. The release contains the merged commit according to the tag comparison. This was a documentation-only resolution: upgrading does not change run_stream() to prioritize later structured output.
If it still fails
run_stream()still stops at the first matching output and does not execute subsequent tool calls. The v2.73.0 documentation retains this rule.- Allowing text in
output_typestill permits the model to choose text. Switching methods addresses the text-before-output-tool case; it does not force the model to produce a structured tool call.
Not for: Pydantic AI nested run_sync() freezes inside synchronous output functions.
Sources
- Structured Output fails with text output + Behaviour inconsistency, IngLP, opened 2025-04-25; closed as completed on 2026-11-03: "I want a structured output."
- Document that
run_stream()takes text streamed before an output tool call as the output, dsfaccini, merged 2026-11-03; closed. - v2.66.0, published 2026-11-04.
- Release ancestry comparison, release tag compared with the merged commit.
- Output documentation at v2.73.0.
- v2.73.0, published 2026-11-24.
Checked
2026-11-24; read the issue and comments, PR API record, release API records, tag comparison API record, and output documentation at v2.73.0; no command was run.
Started from a post by @IngLP, packaged by the editor. Original post