Constrained Generation in AI
From the AI Prompting cheat sheet · Advanced Prompting Patterns · verified Jul 2026
Constrained Generation
Set boundaries and rules for outputs
javascript
NAME: Rule-Based Constraints
PURPOSE: Define specific constraints and validation rules for outputs
TEMPLATE:
Generate [OUTPUT TYPE] with these constraints:
MUST include:
- [REQUIRED ELEMENT 1]
- [REQUIRED ELEMENT 2]
- [REQUIRED ELEMENT 3]
MUST NOT include:
- [FORBIDDEN ELEMENT 1]
- [FORBIDDEN ELEMENT 2]
Rules:
- [RULE 1]
- [RULE 2]
- [VALIDATION CRITERIA]
If any constraint cannot be met, explain why and provide the closest alternative.
EXAMPLE:
Generate a password policy with these constraints:
MUST include:
- Minimum length requirement
- Character type requirements
- Expiration policy
MUST NOT include:
- Specific passwords as examples
- Requirements impossible on mobile devices
- Discriminatory language
Rules:
- Be compatible with NIST guidelines
- Support international characters
- Maximum 5 rules total
If any constraint cannot be met, explain why and provide the closest alternative.
OUTPUT:
**Corporate Password Policy**
1. **Minimum Length**: Passwords must be at least 12 characters long
2. **Character Requirements**: Must include at least 3 of the following:
- Uppercase letters (A-Z)
- Lowercase letters (a-z)
- Numbers (0-9)
- Special characters (!@#$%^&*)
- Unicode characters supported
3. **No Forced Expiration**: Passwords are not rotated on a schedule; require a change only on evidence of compromise (per NIST SP 800-63B-4)
4. **Password History**: Cannot reuse last 12 passwords
5. **Account Lockout**: 5 failed attempts triggers 30-minute lockout
All requirements comply with NIST SP 800-63B-4 guidelines and support mobile device entry.⚠️ Clearly separate must-have from nice-to-have
📌 Include fallback instructions
🟢 Specify validation criteria upfront