Structured output
Structured output gives an application typed data instead of prose it must interpret. A response schema describes the fields you need. Hashbrown parses the arriving response into that shape, and your application decides how to display or use it.
Use it for extracting form values, classifying a request with explanations, or producing a proposal for review. Choose generative UI when the model should also choose components. A valid shape is one part of accepting a result: completion, business rules, and permission to perform a write still belong to the application.
Typed output is input to application review
Scroll horizontally to see the full diagram, or expand it.
Read the diagram
A response schema and streamed model text both feed the parser. The parser yields typed values for application display and review. Completion and domain checks remain separate from parsing.
Extract a book request
Use the endpoint and client configuration from the Quickstart. Keep provideHashbrown in appConfig and the <app-root> host. Import the standalone class below into main.ts and pass it to bootstrapApplication() with that same appConfig. The endpoint must preserve the client response schema and use a provider that supports it.
import { Component } from '@angular/core';
import { structuredChatResource } from '@hashbrownai/angular';
import { s } from '@hashbrownai/core';
const readingSchema = s.object('A request for a book', {
title: s.string('The requested book title'),
author: s.string('The author named by the user'),
copies: s.integer('How many copies are requested', {
minimum: 1,
maximum: 20,
}),
});
@Component({
selector: 'app-root',
template: `
<button type="button" [disabled]="chat.isLoading()" (click)="request()">
Generate
</button>
@if (chat.isLoading()) {
<p role="status">Preview — still generating</p>
}
@if (chat.error()) {
<p role="alert">The request failed.</p>
}
@for (message of chat.value(); track $index) {
@if (message.role === 'assistant') {
<p>{{ message.content?.title }} — {{ message.content?.author }}</p>
<p>Requested copies: {{ message.content?.copies }}</p>
}
}
`,
})
export class ReadingRequest {
readonly chat = structuredChatResource({
system:
'Extract the title, author, and requested copy count from the user message.',
schema: readingSchema,
});
request(): void {
this.chat.sendMessage({
role: 'user',
content: 'I need two copies of Pride and Prejudice by Jane Austen.',
});
}
}
This interface displays the extracted data for review. It does not reserve books. Before adding a reservation action, require successful completion, check the finish reason and current request, validate inventory and counts, and authorize the server write.
For incomplete input, define an explicit clarification branch with s.anyOf rather than forcing the model to fill missing required fields. The schema guide shows tagged response alternatives.
Explore it in the workbench
The workbench below replays a recorded run of this lesson.
Watch a plain typed plan stream into an application-rendered card, then accept and revise it.
Recorded in the real Angular workbench with OpenAI requests, browser tools, Hashbrown streaming, and application state. Footage slowed to half speed for readability. Replay reads captured frames. No narration. Read the text walkthrough.
Let’s use the same two-step plan, this time as typed data. The model returns a title and two steps. Hashbrown parses the response as it streams, and our application renders those values.
I like keeping the example familiar. In Generative UI, the model selects SummaryCard from a catalog. Here, structuredChatResource() returns plan data and the application chooses how to display it.
Run the same conversation
Use the panel above, or run the workbench on your machine.
The replay uses this checked Angular client with real provider requests. The local server keeps credentials, instructions, tools, and response schema on the server. Refresh clears the in-memory conversations and accepted plan.
Describe the plan
The shared schema describes a title and a streaming array of step strings. Both frameworks and the server use this same contract.
export const workbenchPlanSchema = s.object('A two-step plan proposal', {
title: s.string('A concise plan title'),
steps: s.streaming.array(
'Exactly two concise steps',
s.string('A clear action'),
),
});
s.streaming.array lets resolved steps appear before the whole response finishes. It does not mean the plan is ready to accept. The workbench also checks application rules: a nonempty title of at most 120 characters and exactly two nonempty steps, each at most 200 characters.
Request typed data
The checked Angular client uses structuredChatResource() with the plan schema, the same read-only readContext tool, and the capturing transport:
readonly chat = structuredChatResource({
system: workbenchStructuredSystem,
schema: getWorkbenchPlanSchema(
getWorkbenchLesson(window.location.search).id,
),
transport: createWorkbenchTransport(
this.store,
undefined,
getWorkbenchLesson(window.location.search).endpoint,
),
tools: [
createTool({
name: 'readContext',
description:
'Read the accepted application plan and revision without changing state.',
handler: async () => {
const result = this.store.getSnapshot().application;
this.store.record('tool', { name: 'readContext', result });
return result;
},
}),
],
});
The latest assistant message exposes its parsed plan in content. The application renders that data into its plan card. There is no generated component tree in this lesson.
Read the checked Angular implementation. It includes the rendered card, captured origins, cancellation, and explicit acceptance.
Watch the preview become a result
Send the first prompt. Keep JSON selected to see response text arrive beside the plan. The Typed plan section beside it shows values resolved by the SDK. Select State before accepting: the application still has revision 0 and no accepted plan.
Accept a completed plan
Select Accept plan after the successful response completes. The handler rechecks the plan at the action boundary, copies only validated fields, and advances the application revision. Then send “Make the second step shorter.” The tool reads the accepted plan and the response proposes a revision.
A partial response is a preview. A failed, cancelled, truncated, stale, or already accepted result cannot be applied. A failed follow-up keeps the accepted plan. Selecting a historical timeline moment cannot change live application state.
This example stores the accepted plan in browser memory. Enforce authorization and validation separately for any server write.
Keep the response schema intact
Hashbrown sends the schema in RunAgentInput.forwardedProps.hashbrown.responseSchema. The provider adapter uses that schema, while the client parses streamed text into typed content. Hashbrown does not add an output tool to request structured output.
The local workbench endpoint pins its own schema for each lesson. If you customize your endpoint, preserve the schema your feature needs. The secured text-only endpoint deliberately removes browser-supplied schemas as part of its different policy.
Next steps
Use Streaming to explore the streaming markers, then Natural language forms to connect typed data to a form. See Skillet schemas for supported schema inputs and constraints, or Tools to follow the plan’s context read.
