FullStack AI Hub
Studio
lesson depth
Mastery
not started · 0%

Rendering Streaming Thought Blocks

Render only explicitly user-visible summaries and status events from typed streams; keep private reasoning out of transcripts and assistive views.

Freshness: current•13 min read•AI User Experience and Human-AI Interaction
Full Technical Reference Document

Mental model

A “thought block” in an application is only a presentation category; it does not authorize exposing internal model reasoning. Render a block only when the provider or product contract identifies it as user-visible content, such as an approved summary or progress status. Treat typed stream parts, visibility policy, and transcript persistence as separate concerns.

Theory

Streaming APIs carry typed events because message text is not the only information a client may need. A protocol can signal text deltas, tool input, sources, errors, finish events, or provider-specific reasoning parts. The fact that a part has a reasoning label describes its stream type; it does not say that the application should place its contents in the user’s transcript. A renderer needs an explicit allow-list that maps protocol parts to product-approved views.

Use three separate representations. The wire decoder receives transport events and validates their ordering and shape. A presentation reducer selects text and explicitly approved summaries or status messages. A persistence layer stores only the parts the product intends to retain in chat history. An implementation that simply serializes every decoded part can expose content that was meant for internal orchestration or create a transcript that cannot be safely shared.

For a candidate block (b), define its display decision as:

render⁡(b)=P(b)∧U(b)∧S(b)\operatorname{render}(b) = P(b) \land U(b) \land S(b)

Here (P(b)) means a trusted provider adapter marked the block as eligible, (U(b)) means product policy permits that block type for this user and surface, and (S(b)) means its schema and message identity validated. Each is a dimensionless Boolean predicate, not a model-confidence score. If any check fails, do not render or persist the block; continue to show permitted answer text and a generic process status where useful.

Consider a stream with three answer text deltas, four reasoning-delta parts, one server-generated data-public-summary part, and a finish marker. A safe reducer appends the three answer deltas, ignores the four raw reasoning parts, and presents the public summary only after the server adapter has validated it. The finish event closes the response state. The UI may show “Checking a source” while a tool runs without showing the model’s private reasoning text.

Decode typed stream part
Validate protocol sequence and message ID
Apply product visibility allow-list
Render approved text or summary
Persist only permitted transcript parts
Conceptual teaching model synthesized from:vercel-ai-sdk-ui-stream-protocol,openai-api-reference,human-ai-guidelines

Reducing the stream to a safe view

The reducer below demonstrates the boundary. A trusted server adapter is responsible for emitting a custom data-public-summary only after the summary is authorized for display; the client still validates that it received a string. Raw reasoning deltas are deliberately not accumulated in view state:

typescript
type StreamPart =
| { type: "text-delta"; delta: string }
| { type: "reasoning-delta"; delta: string }
| { type: "data-public-summary"; data: { summary: unknown } }
| { type: "finish" };
​
type ChatView = {
answer: string;
approvedSummary: string;
complete: boolean;
};
​
export function reducePart(view: ChatView, part: StreamPart): ChatView {
if (part.type === "text-delta") {
return { ...view, answer: view.answer + part.delta };
}
if (part.type === "data-public-summary") {
if (typeof part.data.summary !== "string") return view;
return { ...view, approvedSummary: part.data.summary };
}
if (part.type === "finish") {
return { ...view, complete: true };
}
return view;
}

The custom summary channel is a product contract, not a trick for relabeling private text. If the provider does not supply a user-visible summary or the adapter cannot establish its provenance, omit that block. Keep status such as tool progress in a separate ephemeral field and decide whether it belongs in history. Include stable message and part IDs so duplicate or reordered events can be rejected rather than rendered twice.

Failure modes and misconceptions

FailureWhy it is unsafe or confusingControl
Render every event whose type contains reasoningInternal stream data can be mistaken for a public explanationAllow-list only explicitly approved user-facing part types
Persist the raw wire event arrayHidden or transient data can leak into exports, logs, or future promptsPersist a normalized transcript view with explicit retention rules
Trust a client-provided visibility flagThe browser can be modified and is not the policy authorityEnforce visibility in a trusted server adapter and validate again on the client
Reuse part IDs across messagesA stale summary can overwrite the current responseScope IDs to a message and reject unexpected ordering
Treat a summary as a faithful transcript of internal reasoningA summary is a distinct user-facing artifact, not proof of how the model reasonedLabel it accurately and avoid claims of complete internal transparency

Typed streams can evolve as SDKs add events. Unknown parts should be ignored or handled through a safe fallback, not coerced into text. Validate that start/delta/end events are consistent when the protocol requires them. On abort or error, close the visible response state and leave the last permitted answer intact; do not render a raw error payload without escaping and policy checks.

Trade-offs

Showing a concise approved summary may help users understand what the system is doing, but it can omit uncertainty or relevant process details. Showing only a generic status protects private channels but provides less explanation. Separate an operational status such as “Searching two sources” from any explanation of a decision, and attach citations to the final answer when evidence is available. Users should be able to distinguish a summary, a source citation, and an answer claim.

Some stream protocols expose reasoning parts for orchestration, debugging, or specific product experiences. Protocol availability does not determine the interface policy. Follow provider terms, product rules, and privacy requirements; never infer that raw internal reasoning is a public explanation. Keep ephemeral state out of persistence and telemetry unless its retention is explicitly justified.

Decision scenario

A frontend receives reasoning-start, several reasoning-delta parts, a final answer, and a separate short summary that a trusted adapter has marked user-visible. A product manager asks to show every block under a “How I thought” heading. Continue streaming the answer, ignore the raw reasoning deltas, and display the approved summary only if the product policy permits that surface. Persist only the approved answer and summary fields, then audit the rendered DOM and transcript export for accidental raw-part inclusion.

Learning outcomes

  • Explain why a stream part’s protocol type does not itself authorize display or persistence.
  • Design an allow-listed reducer for answer text, status, and approved summaries.
  • Test duplicate, unknown, reordered, aborted, and unauthorized stream parts at both rendering and transcript boundaries.
Reflect before revealing the guide

Prerequisites & Related Concepts (2)

Private notes

0 words
Recommended Free Track
Free · Verifiable Credential

FS-501AI Evaluation and Reliability

Turn product intent and risk into representative evaluations release gates traces service targets and continuously improving regression evidence.

17 concepts~22h self-paced
Start Free Course
Weekly Engineering Dispatch

Get the weekly systems teardown

One technical note per week covering inference bottlenecks, retrieval harnesses, and commit-pinned teardowns.

Next