Advanced Prompt Engineering / Advanced Prompt Structures

Constraint Specification

Beginner [2/5]
Boundary definition Limitation setting

Definition

Constraint specification explicitly defines limits and requirements for LLM outputs. Constraints tell the model what it must do, what it must not do, and the boundaries within which it should operate.

Well-specified constraints are essential for production systems where output predictability and safety are critical.

Key Concepts

  • Positive constraints: What the model MUST do (include X, use Y format)
  • Negative constraints: What the model must NOT do (never mention, avoid)
  • Format constraints: Structure, length, style requirements
  • Content constraints: Topics, information, or claims to include/exclude

Examples

Length Constraints
Word/Character Limits
Constraints: - Response must be exactly 3 sentences - Each sentence must be under 20 words - Total response under 280 characters (for Twitter)
Content Constraints
Information Boundaries
Constraints: MUST include: - Product name in first sentence - At least one customer benefit - Call to action at the end MUST NOT include: - Competitor names - Pricing information - Unverified claims
Behavior Constraints
Action Limits
Constraints: - Never provide medical diagnoses - Always recommend consulting a professional - If unsure, say "I don't know" instead of guessing - Decline requests outside your defined scope

Interactive Exercise

Add Constraints

Add constraints to this prompt for a children's story generator:

Base: "Write a short story for children."

Pro Tips
  • Be explicit—vague constraints get vague compliance
  • Use MUST/MUST NOT for clarity
  • Test constraints with adversarial inputs
  • Prioritize constraints—models may trade off when conflicts arise

Related Terms