🧱This template showcases how to output structured responses with a LangChain.js chain and the Vercel AI SDK in a Next.js project - by: RenanGeorgio.
☎️The chain formats the input schema and passes it into an OpenAI Functions model, then parses the output.
💻You can find the prompt, model, and schema logic for this use-case in app/api/chat/structured_output/route.ts.
📊By default, the chain returns an object with tone, word_count, entity, chat_response, and an optional final_punctuation, but you can change it to whatever you'd like!
💎It uses a lightweight, convenient, and powerful schema validation library called Zod to define schemas, but you can initialize the chain with JSON schema too.