Prompt Engineering Tutorial 0/120 lessons ~6 min read Lesson 24
Constraints in Prompts
Constraints tell the model what NOT to do, how long to be, what to refuse, what voice to avoid.
Course progress0%
Focus
6 guided sections
Practice signal
Examples included
Career prep
Foundation builder
Introduction
Constraints tell the model what NOT to do, how long to be, what to refuse, what voice to avoid. They're the guardrails that keep output usable.
Beginner analogy: Like dietary restrictions on a recipe — 'no nuts, gluten-free, under 20 minutes'. Constraints shape the dish without prescribing it.
Understanding the topic
Core concepts to understand:
- Length: 'under 100 words', 'exactly 3 bullets'.
- Tone: 'professional, no emojis', 'casual, friendly'.
- Content: 'no medical advice', 'no personal opinion'.
- Format: 'no markdown', 'JSON only'.
- Refusals: 'if unsure, reply EXACTLY: I cannot answer'.
Syntax reference
Visual workflow / architecture:
bash
Constraints checklist:☑ length ≤100 words☑ tone professional☑ content no claims about effectiveness☑ format JSON, no comments☑ refusal say "I don't know" if unsure
Real-world use
Legal, medical and financial AI assistants use heavy constraint sections to stay compliant.
Best practices
- Constrain less than you think — too many constraints reduce quality.
- Always include a refusal pattern.
- Test constraints with adversarial inputs.
Hands-on exercise
Interview preparation — practice these questions:
- Q1. Why are constraints important in production?
- Q2. Where do constraints go in the prompt?
- Q3. How can constraints reduce hallucinations?
- Q4. How do you test that constraints hold?
Ready to mark this lesson complete?Track your journey across the entire course.