π§±This template showcases how to output structured responses with a LangChain.js chain and the Vercel AI SDK in a Next.js project.
βοΈ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.
π¨The main frontend logic is found in app/structured_output/page.tsx.