vercel-labs / vercel-labs/ai-python

Structured output streaming: no way to see the object while it generates

Open
#272 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
184
Forks
23
Avg merge
4d 8h
Merged PRs (30d)
24

Description

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing the ai.stream() event flow and the Stream output state, then inspect how Agent.run forwards model stream events. Done means partial output events are emitted when accumulated JSON parses differently, Stream.partial_output exposes the latest plain-dict snapshot, and stream.output remains validated after completion.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
api
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.