Skip to content

What is negative prompting and how do you instruct models what not to do?

Beginner · 2 min read · Prompt Engineering

Open in study mode to save this question and track progress

Short answer: Negative prompting explicitly specifies prohibited behaviors, restricted topics, or disallowed words, preventing model hallucinations, off-topic rambling, and safety policy breaches.

Detail

LLMs process text by predicting tokens that align with prompt semantics. Naive negative instructions like "Do NOT think of a pink elephant" often inadvertently increase attention weight on the banned concept.

Weak Negative Prompt:   "Don't generate conversational intros." (Model often outputs "Sure! Here is...")
Strong Negative Prompt: "Respond strictly with the target JSON object. Zero conversational filler or introductory text."

Best Practices for Negative Directives

  1. Positive Replacement: Instead of solely banning a behavior, instruct the model on the positive alternative (e.g. "Instead of bullet points, use a single continuous paragraph").
  2. XML Tag Isolation: Wrap negative rules inside distinct structural blocks (<disallowed_actions>).
  3. Structured Validation Guardrails: Pair negative prompts with Pydantic output validation to catch edge-case violations.

Example

Python prompt comparison highlighting positive framing of negative constraints:

python
# Weak
prompt_weak = "Write a summary. Do not include pricing or competitor names."

# Strong
prompt_strong = """Write a product summary.
DISALLOWED:
- Do NOT mention pricing or competitor brand names.

REQUIRED FORMAT:
- Focus exclusively on technical product specifications and core features."""

Interview tips

  • Explain why LLMs sometimes ignore negative constraints (due to token-level self-attention activating mentioned concepts).
  • Mention combining negative prompts with output guardrail classifiers like Llama Guard or regex validators.

Related Concepts


⬅ Back to Prompt Engineering · All topics