Prompt Engineering: The Schema Is the Contract
A schema is the list of fields an answer must have. The schema is the contract between the prompt and the reply.
A schema with named fields
The prompt lists each field and its type.
Give the status of order 1042 as JSON. The schema is order_number as a number, customer as a string, product as a string and status as a string. All four fields are required.A schema with a required field
The prompt marks the tracking field as required.
Give the status of order 1042 as JSON. The schema is order_number as a number, customer as a string and tracking as a string. The tracking field is required.A schema for a product
The same idea works for a product, not only an order.
Describe the Aurora Ceramic Mug as JSON. The schema is name as a string, price as a number and dishwasher_safe as true or false. All three fields are required.Example
Give the status of order 1044 as JSON. The schema is order_number as a number, customer as a string, product as a string and status as a string. All four fields are required.Key points
- A schema names each field and the type of value it holds.
- A field can be required or optional. A required field must appear in every reply.
- A type says what the value looks like. A number is not a string.
- The prompt states the schema. The model fills the schema with facts.
- A clear schema gives the same shape on every reply. A vague schema gives a different shape each time.
This example runs the schema prompt for order 1044 against the local model and shows the reply it gave.
Note
A schema is a promise about shape, not about truth. The facts must still come from the shop data.
Try it Yourself
Edit the code, then press Run.
Running is simulated · Rust Playground
Exercise
What is a schema?