Keyboard Shortcuts N Next post
P Previous post
S Save / unsave
R Read aloud
T Toggle theme
/ Focus search
Esc Close panels
🔥
Ready to read...
Constraints GitHub Copilot IMCSEIAN intermediate Negative Prompts Prompting Tutorial

Negative Prompts: Telling Copilot What NOT to Do

Reviewed & accurate
AI Summary
IMCSEIAN · GitHub Copilot Master Course

Negative Prompts: Telling Copilot What NOT to Do

Constrain output by exclusion — 'don't use X library', 'no comments', 'no try/except'.

Phase 2 — Intermediate Lesson IN-07 Difficulty: Intermediate 8 min read
Course: GitHub Copilot Phase 2 — Intermediate 8 min read Last verified: 2026-08-30

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 Copilot what NOT to do is more effective than telling it what to do. 'Don't use lodash' is clearer than 'use only vanilla JS'. Negative prompts are a precision tool for narrowing output.

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 the model.

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 Copilot suggest that you don't want? Specific libraries, patterns, styles?

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 Copilot 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). Copilot kept suggesting classes. Adding 'Don't use classes. Prefer functions and closures.' to the system prompt cut class suggestions by 90%. The remaining 10% were caught in review.

Example Prompts / Commands / Code

Negative prompt examplesimcseian
# 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).

# Refactor:
Refactor this function.
Constraints:
- Don't change the public API.
- No new dependencies.
- No comments unless behavior changes.

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 negatives short — 3–5 max per prompt.
  • Maintain a per-project 'don'ts' list in copilot-instructions.md.
  • Iterate when negatives are ignored — rephrase more specifically.

Troubleshooting

ProblemHow to Fix
Negative ignoredRephrase: 'no try/catch' → 'do not use try/catch; use Result type from neverthrow'.
Too many negativesMove stable ones to .github/copilot-instructions.md.

Practical Exercise

Your Turn

Identify 3 patterns Copilot suggests that you don't want. Add negative constraints to your next prompt. Verify they're respected.

Professional Challenge

Stretch Goal

Build a per-project 'don'ts' list in .github/copilot-instructions.md. Commit. Verify Copilot respects them across all Chat in the repo.

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' in copilot-instructions.md.

Frequently Asked Questions

Do negatives work for inline completions?
No — only for Chat and CLI. Use copilot-instructions.md for inline.
Can I have too many negatives?
Yes — model can't satisfy all. Move stable ones to copilot-instructions.md.

Further Reading

Official References

Related lessons: IN-05, IN-39

SEO Metadata

SEO title: Negative Prompts: Telling Copilot What NOT to Do

Meta description: Constrain output by exclusion — 'don't use X library', 'no comments', 'no try/except'.

Primary keyword: negative prompts

Secondary keywords: negative prompts: telling copilot what not to do

Search intent: Informational

URL slug: /negative-prompts-copilot-exclusion

Categories: AI Tools, GitHub Copilot

Tags: GitHub Copilot, Intermediate, Negative Prompts, Constraints, Prompting, IMCSEIAN, Tutorial, IMCSEIAN

Featured image concept: IMCSEIAN lesson card for Negative Prompts: Telling Copilot What NOT to Do

Test Your Knowledge
How did you find this?

Comments

Join the discussion! Sign in with your Google or Blogger account, or comment as Anonymous - no account needed. For quick questions, also reach me on Telegram @cytestch.

Comments