Artificial intelligence • Original RRTutors lesson
Prompt Design and Structured Outputs
Write clear instructions, provide relevant context, set constraints, and validate machine-readable responses.
Concept and explanation
A prompt describes a task to a generative model using instructions and context. Specific goals, examples, output schemas, and explicit unknown handling can improve consistency. Prompting is not a security boundary: user input may conflict with instructions, and outputs must be parsed and validated.
How to apply it
Separate trusted instructions from untrusted content, request a defined schema, validate every field, and test adversarial and ambiguous inputs.
Worked example
An extraction prompt can ask for dates from a document and return null when no date is present, followed by schema and source-span checks.
Illustrative Python example
request = {
"task": "extract invoice fields",
"output": {"invoice_id": "string|null", "total": "number|null"},
"rule": "return null when evidence is absent",
}
print(request)
Expected result
A schema clarifies the desired shape but still requires application-side validation.
Limitations and cautions
A prompt cannot enforce authorization, prevent every injection, or guarantee that extracted values are correct.
Practice exercise
Design a structured extraction prompt and specify validation for missing or malformed values.
Key takeaway: Reliable AI applications validate outputs at the boundary.