All posts
prompt-engineeringstructured-outputllm

Structured Output Prompts: Ready-to-Use Templates

Copy-paste structured output prompts with real examples, plus what to change for your own use case.

SR

Suhail Roushan

August 6, 2026

·
6 min read
·
0 views

Generic prompts give you prose when you need objects, arrays, and validated fields — these templates fix that by forcing the model into a schema you can parse.

Structured Output Prompts solve the most annoying problem in LLM integration: getting consistent, typed data back instead of freeform text. I've tested these against Claude, GPT-4, Gemini, and DeepSeek, and they hold up across all four. The key isn't asking nicely — it's defining the contract before the model starts generating. Below are three templates I use in production, from simple to adversarial.

Why Generic Prompts Fail Here

The failure mode is specific: you ask for "a list of users" and get a paragraph with prose, bullet points, or — worst case — a markdown table. Then you write regex to extract what should have been JSON. Structured Output Prompts fail differently — they fail loudly with missing fields or wrong types, which your parser can catch immediately.

Generic prompts also let the model "help" by adding explanations around your data. That's poison for automated pipelines. When you're calling an LLM from a backend service, you need deterministic structure, not conversational generosity.

Template 1: The Schema-Bound JSON Extractor

You are a data extraction engine. Extract the requested information from the input text and return ONLY valid JSON.

Input text:
{{INPUT_TEXT}}

Required output format:
{
  "entities": [
    {
      "name": "string (full name or organization name)",
      "type": "string (one of: PERSON, ORGANIZATION, LOCATION, DATE)",
      "confidence": "number (0.0 to 1.0, based on how certain you are)",
      "mentions": "integer (count of times this entity appears)"
    }
  ],
  "summary": "string (max 50 words, factual only)"
}

Rules:
- Return ONLY the JSON object. No markdown fences, no commentary.
- If an entity type is ambiguous, choose the most likely based on context.
- Do not invent entities that are not explicitly in the input.
- If confidence is below 0.5, still include the entity but flag it with a lower score.

Placeholders: {{INPUT_TEXT}} is your raw text. The confidence field is the critical addition — it lets you filter low-quality extractions downstream. I use this template for scraping job listings and news articles into structured tables.

Template 2: The Multi-Step Reasoning Chain

You are a structured reasoning engine. Solve the problem step by step, but return ONLY a JSON object with your intermediate steps and final answer.

Problem:
{{PROBLEM_DESCRIPTION}}

Output schema:
{
  "steps": [
    {
      "step_number": "integer (starting at 1)",
      "description": "string (what you did in this step)",
      "intermediate_result": "string or number (the output of this step)"
    }
  ],
  "final_answer": "string or number (the definitive answer)",
  "confidence": "string (one of: HIGH, MEDIUM, LOW)",
  "assumptions": "array of strings (any assumptions you made)"
}

Rules:
- The "steps" array must have at least 3 entries for any non-trivial problem.
- Each step must reference the previous step's result.
- If you cannot solve it, set final_answer to "UNSOLVABLE" and explain why in assumptions.
- Return ONLY valid JSON. No thinking out loud outside the JSON.

Placeholders: {{PROBLEM_DESCRIPTION}} is your task. The assumptions array is the hidden gem — it surfaces edge cases the model noticed but you didn't ask about. I use this for code review bots and math word problems where I need to audit the reasoning path.

Template 3: The Adversarial Edge-Case Handler

You are a validation engine. Given the input, identify all violations of the stated rules, and return a structured report.

Rules to enforce:
{{RULES_LIST}}

Input to validate:
{{INPUT_TO_CHECK}}

Output schema:
{
  "is_valid": "boolean (true only if ALL rules pass)",
  "violations": [
    {
      "rule_id": "string (use the rule number or name from the rules list)",
      "severity": "string (one of: CRITICAL, WARNING, INFO)",
      "message": "string (specific explanation of what failed)",
      "suggested_fix": "string (concrete action to resolve it)"
    }
  ],
  "edge_cases_detected": [
    "string (any ambiguous inputs, boundary conditions, or unusual patterns you noticed)"
  ]
}

Rules:
- If is_valid is true, violations must be an empty array.
- Do not soften CRITICAL violations to WARNING to make the output look better.
- If the input is ambiguous, do not guess — add it to edge_cases_detected and set is_valid to false.
- Return ONLY valid JSON.

Placeholders: {{RULES_LIST}} and {{INPUT_TO_CHECK}}. This template handles the messy reality where inputs don't cleanly fit your schema. I use it for validating user-generated content against content policies and for checking config files against schema definitions. The edge_cases_detected field catches things your rules didn't anticipate.

How to Adapt These for Your Own Codebase

First, wrap each template in a function that injects your dynamic values. Don't paste prompts inline — you'll end up with inconsistent versions across your codebase. Define your prompts as constants, ideally in a dedicated prompts.ts file with TypeScript types for the expected response.

Second, add a validation layer that parses the model output with a schema validator like Zod. Never trust the model to return valid JSON even with these prompts — models occasionally hallucinate extra fields or drop required ones. Zod's .safeParse() gives you a clean failure path instead of a crash.

Third, version your prompts. When you tweak a template, the model's behavior changes. Track prompt versions alongside your code versions so you can debug regressions. I've found that a prompt that worked in June can degrade by August as model weights update.

Do These Prompts Work With Any LLM?

Yes, with caveats. Claude and GPT-4 follow these templates most reliably — they're best at respecting "return ONLY JSON" instructions. Gemini is comparable but occasionally wraps output in markdown fences despite the instruction. DeepSeek follows the schema but sometimes interprets confidence ranges differently (treating 0.9 as "very sure" vs. "probabilistic"). The templates are model-agnostic, but you should test each one against your target model and adjust the rules section if needed. For production, always add a retry loop that re-prompts once if validation fails — that recovers from most format drift.

The single adjustment that improves these prompts the most: add an example of the expected output inside the prompt itself. One concrete example of valid JSON output outperforms ten lines of rules about what not to do.

Related posts

Written by Suhail Roushan — Full-stack developer. More posts on AI, Next.js, and building products at suhailroushan.com/blog.

Get in touch