Problem
With output_type=<pydantic model>, ai.stream() emits text deltas but the parsed object only exists after the stream ends (stream.output). Consumers rendering progressive results — live forms, tables, status panels — cannot show the object taking shape. The TypeScript AI SDK's streamObject() supports this and it's a common expectation coming from that ecosystem (pydantic-ai streams validated partials as well).
Suggested behavior
Emit a PartialOutput event after each text delta that changes the parse of the accumulated JSON, carrying the best-effort partial as a plain dict, plus a Stream.partial_output property for the latest snapshot.
Design notes:
- partials are deliberately unvalidated dicts — validating incomplete JSON is meaningless;
stream.output stays the validated contract
- parsing uses
json_repair with stream_stable=True so truncated values remain verbatim strings instead of being creatively repaired mid-stream
- agent runs forward model stream events unchanged, so this surfaces through
Agent.run for free
Happy to take this one.
Problem
With
output_type=<pydantic model>,ai.stream()emits text deltas but the parsed object only exists after the stream ends (stream.output). Consumers rendering progressive results — live forms, tables, status panels — cannot show the object taking shape. The TypeScript AI SDK'sstreamObject()supports this and it's a common expectation coming from that ecosystem (pydantic-ai streams validated partials as well).Suggested behavior
Emit a
PartialOutputevent after each text delta that changes the parse of the accumulated JSON, carrying the best-effort partial as a plain dict, plus aStream.partial_outputproperty for the latest snapshot.Design notes:
stream.outputstays the validated contractjson_repairwithstream_stable=Trueso truncated values remain verbatim strings instead of being creatively repaired mid-streamAgent.runfor freeHappy to take this one.