🎓 A1Learner
🔍
0 of 50 lessons completed

Prompt Engineering: Constraints and Format

A constraint shapes the answer. A word count, a tone, a list or a table. Constraints are instructions, not wishes.

A vague limit

Short is a wish. The model decides what short means, and the reply can run long.

Write a short reply to Maya about order 1042.

An exact limit

Under 40 words is a rule. The model has an exact limit to follow.

Write a reply to Maya about order 1042 in under 40 words. Order 1042 is shipped and out for delivery.

A format rule

The format names the shape of the answer. A numbered list gives one product per line.

List the five ShopStack products as a numbered list. Give each product's name and price on its own line.

Example

Write a reply to Tom about order 1043 as three short bullet points. His Hearthstone Desk Lamp is still processing and has not shipped yet. Delivery takes 2 to 4 business days once it ships.

Key points

  • A constraint is a rule the answer must follow.
  • A word count keeps the reply short. A tone keeps it warm or formal.
  • A format names the shape of the answer. A list, a table or short paragraphs.
  • Constraints work when they are exact. Short is a wish and under 40 words is a rule.

This example runs a prompt with a format rule against the local model and shows the reply it gave.

Note

A constraint cannot add facts. It only shapes the facts the prompt gives.

Try it Yourself

Edit the code, then press Run.

Running is simulated · Rust Playground

Exercise

Which limit is a rule the model can follow?