TECHNOLOGY

Pydantic AI text deltas bypass output validators

In this article
THE QUICK TAKE

Treat raw deltas as display fragments, and choose an explicit validated final-output path before saving or acting on generated text.

Separate display fragments from accepted text

A client appends every arriving text fragment to a report preview. An output validator normally checks that source identifiers are present and may transform the text. Pydantic AI’s output guide states that stream_text(delta=True) returns raw deltas and skips output validators. Smooth incremental display therefore does not establish that the displayed content passed the application’s ordinary final-output acceptance rule.

Compare delta and snapshot consumption

The result API distinguishes deltas from accumulated text. With snapshot consumption, each value represents text accumulated so far; the guide says validators can transform those snapshots. Appending snapshots as though they were deltas duplicates content. Conversely, replacing the entire document with each delta drops prior text. Choose the consumer update behavior according to the actual stream representation rather than merely the method’s familiar name.

Keep TextOutput processing explicit

The guide also explains that stream_text does not apply TextOutput functions. Use the documented stream_output path when the intended output is the value produced by such a function. A processing function might normalize references or construct a domain object from text. Reading raw text bypasses that transformation even when the function was configured as part of the agent’s output design; it should not be described as already processed application output.

Preserve the accepted message deliberately

The history guide discusses message availability for streamed runs, and the output guide notes that delta text consumption does not add the final output message to result messages. Do not assume a screen containing the whole report guarantees that the same final message is available for conversation persistence. Define how validated final output and retained history are obtained before building continuation around that assumption.

Assign side effects to a completed validation step

Keep incremental rendering separate from publishing a report or writing an annotation derived from its content. Task contracts establish the completed artifact, while tool observations retain which validation and transformation path produced it. Partial snapshots may invoke validators repeatedly, so validators should not casually publish each intermediate value. A useful implementation accepts one deliberate final result and labels the streaming preview according to the guarantees it actually has.

Earn rental income from GPUs

Have idle GPUs or looking to fund AI infrastructure? Retrivium finds a rental platform, sets up the server and helps you assess income and costs with a pilot.

Explore GPU hosting
← All articles