A language model may understand a request yet return information in an inconvenient or unpredictable shape. Structured output organizes generated information into predefined fields or a machine-readable format, making it easier to review or pass to another application. section 12.3.2 section 7.3.2
Use explicit instructions and examples to make the expected structure clearer:
- Choose the required fields before prompting; JSON is useful because downstream applications can consume it easily. section 12.3.2
- State exact key names and value types when an application depends on them, such as ClaimID rather than ClaimNumber or numeric values rather than strings. section 12.3.2
- Add a one-shot example when the model extracts too many fields, duplicates data, invents keys, or uses an unsuitable layout. section 12.3.2 section 7.3.2
- Validate the result against the required format and review content for correctness, completeness, safety, and resilience to prompt injection. section 4.2.2
Extracting claim identifiers
A transcript-extraction prompt can request only TaxID, MemberID, and ClaimID, with numeric values. An unconstrained response may also include names, dates, and duplicate identifiers; a detailed example narrows the response to the desired keys. section 12.3.2
Listing 12.12 An extractive summary with one example
<|instruction|>
Read the following conversation transcript between a user and the automated assistant. Extract all IDs in JSON format.
Use only the following JSON keys: "TaxID", "MemberID", #1
"ClaimID". #1
The JSON values should be numbers, not strings. #1
<|transcript|> #2
AI: "Welcome to the automated assistant, how can I #2
help?" #2
User: "Claim status" #2
AI: "Ok, claims. What's your Tax ID?" #2
User: "333444555" #2
AI: "Thank you. What's the member's eight-digit Member #2
ID?" #2
User: "55667788" #2
AI: "Ok, and what's the member's date of birth?" #2
User: "April 19, 2024" #2
#2
<|JSON|> #2
{"TaxID": 333444555, "MemberID": 55667788} #2
<|transcript|> #3
<... human-readable transcript removed for brevity ...>
<|JSON|> #4
{"TaxID": 123456789, "MemberID": 87654321, "ClaimID": #5
111222333} #5
Inspect a constrained JSON prompt that specifies permitted keys and numeric values, then compare its compact result with less controlled extraction. section 12.3.2









