Negative Prompts with Claude
Constrain output by exclusion — 'don't use X library', 'no comments', 'no try/except'.
What You Will Learn
- Use negative prompts to exclude unwanted output.
- Combine with positive constraints.
- Recognize when negatives mislead.
- Iterate negatives precisely.
- Build a 'don'ts' list per project.
Why This Matters
Sometimes telling Claude what NOT to do is more effective than telling it what to do. 'Don't use lodash' is clearer than 'use only vanilla JS'.
Concept Explained
Negative prompts exclude patterns: 'don't use X library', 'no comments', 'no try/except', 'no classes'. They work by activating avoidance patterns in Claude.
How It Works
Add 'Don't ...' or 'No ...' lines to your prompt. Combine with positive constraints. Be specific: 'no try/catch, use Result type instead' is better than 'no exceptions'.
Step-by-Step Tutorial
1. Identify unwanted patterns
What does Claude suggest that you don't want?2. Add negative constraints
'Don't use X. No Y. Avoid Z.' Be specific.3. Combine with positives
'Use vanilla JS, no lodash. Use early returns, no nested ifs.'4. Iterate
If Claude still suggests the unwanted pattern, rephrase more specifically.5. Build 'don'ts' list
Maintain a per-project list of conventions to avoid.Real-World Example
A team's codebase banned classes (functional style). Claude kept suggesting classes. Adding 'Don't use classes. Prefer functions and closures.' to the system prompt cut class suggestions by 90%.
Example Prompts / Commands / Code
"""# Code:
Write a function that fetches a user.
Constraints:
- Don't use axios (use fetch).
- No try/catch (use .catch on promises).
- No comments (code should be self-documenting).
- No classes (use functions).
# Tests:
Generate tests.
Constraints:
- No describe blocks (use flat test functions).
- No mocks (use real implementations with test data).
- No beforeEach (set up in each test).
"""
Common Mistakes
- Vague negatives ('no bad code') — meaningless to the model.
- Too many negatives — model can't satisfy all.
- Negatives without positives — model doesn't know what TO do.
- Not iterating when negatives are ignored.
Best Practices
- Be specific: 'no try/catch, use Result type'.
- Combine with positives: 'use vanilla JS, no lodash'.
- Keep 3–5 max per prompt.
- Maintain a per-project 'don'ts' list.
- Iterate when negatives are ignored.
Troubleshooting
| Problem | How to Fix |
|---|---|
| Negative ignored | Rephrase: 'no try/catch' → 'do not use try/catch; use Result type from neverthrow'. |
| Too many negatives | Move stable ones to Project instructions. |
Practical Exercise
Your Turn
Identify 3 patterns Claude suggests that you don't want. Add negative constraints to your next prompt. Verify they're respected.
Professional Challenge
Build a per-project 'don'ts' list in Project instructions. Commit. Verify Claude respects them across all conversations.
Key Takeaways
- Negative prompts exclude unwanted patterns.
- Be specific: 'no try/catch, use Result type'.
- Combine with positives.
- Keep 3–5 max per prompt.
- Maintain per-project 'don'ts'.
Frequently Asked Questions
Do negatives work for all tasks?
Can I have too many negatives?
Further Reading
Official References
SEO Metadata
SEO title: Negative Prompts with Claude
Meta description: Constrain output by exclusion — 'don't use X library', 'no comments', 'no try/except'.
Primary keyword: claude negative prompts
Secondary keywords: claude exclusion prompts, claude dont use, claude constraints
Search intent: Informational
URL slug: /claude-negative-prompts-exclusion
Categories: AI Tools, Claude
Tags: Claude, Intermediate, Negative Prompts, Constraints, Prompting, IMCSEIAN, Tutorial, IMCSEIAN
Featured image concept: Negative prompts excluding unwanted patterns.
Comments
Comments
Post a Comment