Structured data gives an AI response a predictable shape instead of leaving it as raw text. In a product-search interface, JSON product records can be validated, stored in the conversation, and rendered as a table. section 4.3.4
A React implementation follows the response from model to screen:
- Define the expected product shape with a Zod schema, then use the Vercel AI SDK’s generateObject helper to request and validate JSON against it. section 4.3.4
- Expose the product-generation server action through createAI. On form submission, call the action with the user’s request and add the returned products to the conversation. section 4.3.4
- Render product fields in a table. Handle generation failures rather than assuming every request returns usable data. section 4.3.4
Listing 4.11 Including the generateProductList action
export const AI = createAI({
actions: {
generateProductList, #1
},
initialAIState: [],
initialUIState: [],
});
The action registration shows where structured product generation enters the application’s AI interface. section 4.3.4
Provider capabilities matter. In a separate LangChain.js integration, ChatGoogleGenerativeAI rejects structured output configured with method: 'jsonMode' and supports the function-calling method instead. Check the provider implementation and working integration examples when a structured-output call fails. section 8.3.2
const modelWithParser = model.withStructuredOutput(format, {
method: 'jsonMode',
});
const result = await modelWithParser.invoke('Tell me a poem');
Error: ChatGoogleGenerativeAI only supports "functionCalling" as a method.
The failing call makes the unsupported JSON-mode configuration and resulting error concrete. section 8.3.2























