1.13.5
Structured Output Prompts: JSON and XML
What is it?
Structured output prompting asks the model to return information in a predefined format such as JSON or XML. This makes the response easier for software systems to parse and process.
Key points
Specify the required structure. Define field names and expected data types. Provide a schema or example where useful. Use delimiters to separate input data from instructions. Validate the generated output. For stronger structural guarantees, structured prompts can be combined with constrained decoding.
Requesting JSON Output
Prompt: Extract the product name and price from this text. Return JSON with exactly two fields: product_name and price. Input: The product is Wireless Mouse and its price is 799. Expected structure: {"product_name":"Wireless Mouse","price":799}.
Real-world application
Use structured output when connecting LLMs to APIs, databases, ERP systems, reporting pipelines or applications that expect predictable fields.
Key takeaway
Structured output prompts make model responses easier to integrate with software, but validation is still important.