Skip to content

35 min read

Three ways to see it

  1. Most failed AI projects in Pakistani offices die at the same place: the output of the model is correct in substance but wrong in shape. The accountant wants a CSV but gets a paragraph. The HR officer wants a table but gets bullet points. The developer wants JSON but gets JSON wrapped in apologetic English. The substance is fine. The shape is unusable. This single problem accounts for more abandoned automation projects than any actual model limitation. The solution is output format control, and it is one of the most learnable skills in prompt engineering. By the end of this lesson, your model outputs will land in the exact shape your next tool needs them in.

  2. Way one: natural-language formatting. You describe the shape in plain English or Urdu and trust the model. "Return the answer as a bulleted list with five points, each point one sentence, no introduction, no conclusion." This works for casual reports and dashboards but fails for anything a downstream program will parse. The model will mostly comply but will occasionally add a courteous "here is the list you asked for" line that breaks any automatic parser. For human consumption this is fine. For machine consumption this is fragile.

  3. Way two: schema-driven JSON. You give the model the exact JSON schema you want and ask it to fill it. "Return only valid JSON in this schema, no surrounding text, no markdown fences: { ntn: string, taxpayer_name: string, amount_pkr: number, filing_date: string in YYYY-MM-DD }." Frontier models from OpenAI, Anthropic, and Google have all been trained to be good at this. Add "return only JSON, no other text" twice for safety, and modern models will reliably return parseable JSON. If your downstream is code, this is the right level. If your downstream is Excel, you can convert JSON to CSV in one line.

Quick check

Quick check: what makes modern AI different from a rule-based program?

The why-tree

The format hierarchy. Human reader, no parsing: natural language formatting. Machine reader, strict parsing: JSON schema. Both human and machine, with some tolerance: XML tags. Choose the format that matches the next step in your pipeline, not the one that looks impressive.

Sources

Sources. OpenAI's structured outputs documentation at platform.openai.com. Anthropic's guide on using XML tags and tool use for structured outputs. Google AI Studio's controlled generation documentation. The LangChain output parsers documentation, which formalises common patterns. The 2024 paper "Let Me Speak Freely?" by Tam et al. on the cost and benefits of structured-output constraints.