When a person reads a model's reply, clarity is enough. When your program reads it, it must have a fixed shape the program knows in advance. Structured outputStructured outputAsking for the answer in a format a program can read, such as JSON with a given schema. Some APIs guarantee the schema; elsewhere the result must be validated before it is used. means asking for the reply in a format such as JSONJSONA text format for exchanging data, with objects in curly braces, lists in square brackets, and text and number values. Every programming language reads it, and it is the usual format for API requests and structured model output., with set keys and types, and validating it before use.
Describe the shape precisely
Extract the following from the customer's message and answer with JSON only:
{
"intent": "complaint" | "question" | "request",
"order_id": string, or null if no number is given,
"urgent": true or false
}
Add no text before or after the JSON.The promptPromptThe text you give a model to work on, from a short question to long instructions with a role, context, examples and a required format. The quality of the output follows the clarity of the prompt more than its length. says what happens when the information is missing: null. Without that, the model may invent an order number.
Use the provider's feature
Many providers and libraries such as the AIArtificial intelligence (AI)A field that builds programs doing tasks that used to need a human mind, such as understanding language, recognising images and making decisions. Large language models are one small part of it, not all of it. SDK let you pass the schema with the request so the reply follows it. That beats describing it in words, but it does not replace the next step.
Always validate
Model output is untrusted input. In TypeScriptTypeScriptJavaScript with types: you write that this variable is a number and this function returns text, so type checking catches errors before running. It helps models too, since types tell them the shape of the data., zod does it:
import { z } from "zod";
const Reply = z.object({
intent: z.enum(["complaint", "question", "request"]),
order_id: z.string().max(40).nullable(),
urgent: z.boolean(),
});
const parsed = Reply.safeParse(JSON.parse(text));
if (!parsed.success) {
// retry once, then use the fallback
}When the reply does not match
Retry once with the error message; do not retry forever; then fall back to a safe default or a human reviewHuman in the loopAn agent stopping at important steps to wait for a person's approval, such as before deleting files, deploying or sending a message. A little slower, and it stops one mistake from becoming a disaster.. That is how Talqeen works: every AI task has an output schema, one repair attempt, and a fallback that works with no model at all.
Small tips
Keep schemas small, prefer fixed lists over free text, cap the length of every string, and never render the output as HTMLHTMLThe language that describes the content and structure of a web page: headings, paragraphs, links, images and forms. Picking the right tag, such as button rather than div for a button, makes the page clear to screen readers and search engines. without sanitising it.