Task Framing, Few-Shot Examples, and Output Contracts
Good prompts define the desired task and criteria, not just a persona. Include examples when labels or formatting are ambiguous. Keep examples representative and avoid leaking sensitive production data. For classification, define each label and edge cases. For extraction, define required fields, normalization rules, and how missing information should be represented.
Prompt examples can improve consistency but do not replace schemas, validation, or evaluations. A model can still return malformed or semantically invalid content. Validate shape, then validate domain constraints such as date ranges, known product IDs, or allowed categories.
A syntactically valid JSON object can still contain a wrong customer ID, unsafe action, or fabricated value. Validate semantics too.
Task: Extract the appointment details.
Return fields: date, time, timezone, patient_name.
Rules:
- Use null when a field is absent.
- Do not infer a date that was not provided.
- Preserve the user's timezone if stated.
- Do not include commentary outside the requested object.- Use examples for ambiguous edge cases.
- Define how missing fields should be represented.
- Validate both structure and business meaning.
What is the strongest production approach for a fixed output contract?