Module 3 · Chapter 19 Fundamental Prompting Techniques › Negative Prompting

Negative Prompting

Negative prompting tells an AI model what to avoid - unwanted content, behaviour, format, or technology - alongside the desired result, reducing irrelevant, repetitive, unsafe, or incorrectly formatted output.

Quick takeaway: Lead with a clear positive task, then add negative instructions only for known risks or failure patterns - one specific rule per line, with a positive alternative wherever possible. Keep exclusions short, non-overlapping, and free of subjective words like "bad" or "boring."

Introduction

Negative prompting is a prompt design technique used to tell an AI system what it should avoid. Instead of describing only the desired result, the prompt also identifies unwanted content, behaviour, style, format, or implementation choices.

For example, a normal prompt may ask an AI model to write a product description. A negative prompt can further instruct the model not to use exaggerated claims, technical jargon, unsupported facts, or repeated phrases.

Negative prompting is useful because AI models often generate content based on common patterns. Some of those patterns may not match the user's requirements. Clear exclusions help reduce irrelevant, unsafe, repetitive, or incorrectly formatted output.

However, negative prompting must be used carefully. A long list of restrictions can make a prompt difficult to understand. In many cases, replacing a negative instruction with a clear positive instruction produces a more reliable result.

Learning Objectives

After completing this chapter, you should be able to:

  • Explain the meaning of negative prompting.
  • Identify unwanted content in an AI response.
  • Define behaviours that the model should avoid.
  • Write clear exclusion instructions.
  • Compare positive and negative instructions.
  • Use negative prompts for text, code, and image generation.
  • Avoid excessive or conflicting negative constraints.
  • Convert negative rules into positive requirements.
  • Build a reusable negative prompt template.
  • Review whether negative instructions were followed correctly.

Key Terms

TermMeaning
Negative promptAn instruction that tells the model what to avoid
ExclusionContent, behaviour, or format that should not appear
ConstraintA rule that limits the possible output
Positive instructionA statement describing what the model should do
Negative instructionA statement describing what the model should not do
Unwanted contentInformation, words, styles, or elements that should be excluded
Unwanted behaviourAn action or response pattern that the model should avoid
Prompt conflictA situation where two instructions contradict each other
Validation ruleA condition used to check whether the output follows the prompt
Negative prompt fieldA separate input available in some image-generation tools for excluded visual elements

What Is Negative Prompting?

Negative prompting is the practice of explicitly describing what an AI model must not include or must not do.

A negative instruction usually contains words such as:

  • Do not
  • Avoid
  • Exclude
  • Never include
  • Must not
  • Without
  • Remove
  • Omit
  • Do not use
  • Do not generate

A simple negative prompt may look like this:

Prompt
Write a beginner-friendly explanation of Java inheritance.
Do not use advanced mathematical terms.
Do not include unrelated design patterns.
Do not repeat the same definition.
Keep every example focused on inheritance.

The first instruction defines the main task. The remaining instructions define unwanted output.

Negative prompting can control several parts of a response:

  • Subject matter
  • Tone
  • Writing style
  • Output format
  • Technical implementation
  • Programming language features
  • Visual elements
  • Length
  • Repetition
  • Assumptions
  • Unsupported claims
  • Sensitive information

Negative prompting does not guarantee perfect compliance. AI models generate likely outputs based on the complete prompt and available context. A negative instruction reduces the chance of unwanted output, but it does not work like a strict programming rule.

For important tasks, negative instructions should be combined with positive requirements and output validation.

Example:

Prompt
Generate a Java REST API example.
Use Spring Boot 3.
Use constructor injection.
Do not use field injection.
Do not use deprecated APIs.
Return only the controller, service, and repository classes.

This prompt is stronger because it says both what to use and what to avoid.

How Negative Prompting Works

Negative prompting changes the model's understanding of the acceptable output space.

Without exclusions, the model may select any common response pattern related to the task. When exclusions are added, the model attempts to avoid patterns connected to the prohibited elements.

The general process is:

  1. The user defines the main task.
  2. The user identifies unwanted output.
  3. The user writes clear exclusion instructions.
  4. The model interprets the complete prompt.
  5. The model generates a response while attempting to follow both positive and negative constraints.
  6. The output is checked against the exclusions.

Consider this prompt:

Prompt
Explain cloud computing for beginners.
Do not use unexplained abbreviations.
Do not assume the reader has networking knowledge.
Do not include vendor-specific services.
Use one simple real-life example.

The model must understand several requirements:

  • The topic is cloud computing.
  • The audience is beginner-level.
  • Abbreviations must be explained or avoided.
  • Networking knowledge must not be assumed.
  • The explanation must remain vendor-neutral.
  • A simple example must be included.

The negative instructions do not work independently. They are interpreted together with the main task, context, audience, and output requirements.

When Negative Prompting Is Useful

Negative prompting is especially useful when:

  • The model repeatedly includes unwanted information.
  • A specific writing style must be avoided.
  • Certain technologies must not be used.
  • The output must follow strict business rules.
  • Sensitive information must be excluded.
  • The generated content must avoid unsupported claims.
  • Image generation must avoid specific objects or visual defects.
  • The response must not contain explanations, headings, or extra text.
  • The generated code must not use deprecated methods.
  • The user wants to reduce repetition.
  • A known model behaviour needs to be controlled.

Negative prompting may not be necessary when the positive instruction is already clear and complete.

For example:

Prompt
Return the result as valid JSON.

This positive instruction may be better than writing:

Prompt
Do not return paragraphs.
Do not use Markdown.
Do not add headings.
Do not add explanations.
Do not use bullet points.

The positive version is shorter and easier to follow.

Defining Unwanted Content

Unwanted content refers to any information, wording, topic, claim, example, or output element that should not appear in the final response.

Before writing exclusions, identify exactly what would make the output unacceptable.

Common types of unwanted content include:

  • Irrelevant information
  • Repeated ideas
  • Unsupported claims
  • Personal information
  • Sensitive data
  • Offensive language
  • Promotional language
  • Competitor names
  • Outdated information
  • Technical jargon
  • Unrequested examples
  • Fabricated statistics
  • Legal or medical conclusions
  • Placeholder text
  • Excessive disclaimers
  • Internal reasoning
  • Source code when only an explanation is requested
  • Explanations when only code is requested

A weak exclusion is too broad:

Prompt
Do not include bad content.

The phrase “bad content” has no clear meaning. The model cannot reliably determine what the user considers bad.

A better version identifies the exact unwanted elements:

Prompt
Do not include unsupported statistics.
Do not mention competitor products.
Do not make claims that cannot be verified from the provided data.
Do not include pricing information.

Steps for Defining Unwanted Content

  1. Identify the purpose of the output.
  2. List content that directly supports the purpose.
  3. Identify common but irrelevant information the model may add.
  4. Identify information that creates legal, security, privacy, or accuracy risks.
  5. Convert each unwanted element into a specific exclusion.
  6. Remove exclusions that repeat the same rule.
  7. Add a positive alternative where possible.

Example: Business Report

Weak prompt:

Prompt
Write a report about monthly sales.
Do not include unnecessary things.

Improved prompt:

Prompt
Write a monthly sales report using the supplied data.
Do not invent missing revenue values.
Do not include employee performance assumptions.
Do not mention products that are absent from the dataset.
Do not present estimated values as confirmed results.
Label every estimate clearly.

The final instruction provides a positive treatment for estimates instead of only prohibiting them.

Example: Educational Content

Prompt
Explain object-oriented programming to first-year students.
Do not assume prior knowledge of Java.
Do not use framework-specific examples.
Do not introduce design patterns in this lesson.
Do not use unexplained technical terms.
Define each technical term when it first appears.

This prompt keeps the explanation within the correct learning scope.

Defining Unwanted Behaviour

Unwanted behaviour describes how the model should not respond or perform the task.

Content exclusions focus on what should not appear. Behaviour exclusions focus on actions, response patterns, or decision-making methods that should be avoided.

Common unwanted behaviours include:

  • Guessing missing facts
  • Changing the requested format
  • Ignoring input data
  • Repeating the question
  • Adding extra commentary
  • Asking unnecessary questions
  • Producing overly long responses
  • Making assumptions without marking them
  • Revealing private data
  • Using a prohibited tool
  • Modifying unrelated code
  • Renaming existing variables
  • Changing business logic
  • Returning partial output
  • Mixing multiple languages
  • Using humour in formal content
  • Giving a final answer without validation

Example:

Prompt
Review the following Java method.
Do not rewrite the complete class.
Do not change public method names.
Do not alter the method's expected behaviour.
Identify only correctness, performance, and readability issues.
Suggest the smallest safe change for each issue.

The unwanted behaviours are:

  • Rewriting the whole class
  • Renaming public methods
  • Changing behaviour
  • Making unnecessarily large changes

Behaviour-Focused Prompt Structure

A useful structure is:

Prompt
Task: Define what the model must do.
Required behaviour: Define how the task should be performed.
Prohibited behaviour: Define what the model must not do.
Validation: Define how the model should check its output.

Example:

Prompt
Task: Summarise the provided incident report.
Required behaviour: Preserve all dates, system names, and confirmed findings.
Prohibited behaviour: Do not guess the root cause or assign blame.
Validation: Check that every conclusion is supported by the report.

Avoid Personality-Based Negative Instructions

Instructions such as the following are vague:

Prompt
Do not be lazy.
Do not act confused.
Do not give a stupid answer.

These instructions do not define measurable behaviour.

Use task-specific rules instead:

Prompt
Cover every requirement listed in the input.
State clearly when information is missing.
Do not create facts that are absent from the source.
Check the final answer against the requested format.

Exclusion Instructions

Exclusion instructions are direct rules that remove specific content, behaviour, formats, methods, or visual elements from the output.

A good exclusion instruction should be:

  • Specific
  • Relevant
  • Easy to verify
  • Written in direct language
  • Limited to one rule where possible
  • Consistent with other instructions
  • Connected to the main task

Common Exclusion Patterns

Prompt
Do not include [unwanted element].
Avoid using [unwanted style or method].
Exclude [content category] from the response.
Never expose [sensitive information].
Do not assume [unconfirmed condition].
Do not modify [protected component].
Omit [unnecessary section].
Return the output without [unwanted formatting].
Do not use [prohibited technology].
Do not generate [unwanted visual element].

Content Exclusion

Prompt
Write a comparison of Java and Python.
Do not discuss salary, job demand, or company hiring trends.
Focus only on syntax, type systems, runtime behaviour, and common use cases.

Format Exclusion

Prompt
Return the result as a JSON array.
Do not wrap the JSON in Markdown.
Do not include comments.
Do not add text before or after the JSON.

Style Exclusion

Prompt
Write a professional project update.
Do not use humour.
Do not use emojis.
Do not use dramatic or emotional language.
Do not use marketing phrases.

Data Exclusion

Prompt
Analyse the customer feedback.
Do not include names, email addresses, phone numbers, or account identifiers.
Replace customer-specific details with anonymous labels.

Technical Exclusion

Prompt
Generate a responsive navigation menu.
Use HTML, CSS, and plain JavaScript.
Do not use jQuery.
Do not use Bootstrap.
Do not use external JavaScript libraries.

Scope Exclusion

Prompt
Explain exception handling in Java.
Do not cover multithreading, logging frameworks, or Spring exception handlers.
Limit the explanation to try, catch, finally, throw, and throws.

Strong and Weak Exclusion Instructions

Weak instructionImproved instruction
Do not make it badDo not include unsupported claims or unrelated examples
Avoid complex thingsUse beginner-level terms and define each technical term
Do not write too muchLimit the response to 500 words
Do not use old codeUse Java 21 features and avoid deprecated APIs
Do not change anything importantPreserve all public method names and existing business rules
Do not show private dataRemove names, emails, phone numbers, tokens, and account IDs
Do not be repetitiveExplain each concept once and combine overlapping points

Positive vs Negative Instructions

Positive instructions describe the desired output. Negative instructions describe what should be excluded.

Positive Instruction

Prompt
Use constructor injection.

Negative Instruction

Prompt
Do not use field injection.

Both instructions address the same design choice, but they guide the model differently.

Positive instructions are often easier for AI models to follow because they provide a direct target. Negative instructions remove possibilities but may not clearly identify the correct replacement.

For example:

Prompt
Do not write a long answer.

This instruction does not define the acceptable length.

A better positive instruction is:

Prompt
Limit the answer to 150 words.

Similarly:

Prompt
Do not use a complex format.

This can be replaced with:

Prompt
Use five short bullet points.

Comparison

Positive instructionNegative instruction
Defines what should appearDefines what should not appear
Gives the model a direct targetRemoves unwanted options
Usually easier to verifyMay remain open to interpretation
Often reduces ambiguityUseful for known failure patterns
Best for primary requirementsBest for exceptions and exclusions

Combining Both Types

A strong prompt often uses a positive rule followed by a focused negative rule.

Prompt
Write a 300-word beginner-level explanation.
Use short paragraphs and one practical example.
Do not use unexplained technical terms.
Do not include historical background.

The positive instructions define the desired output. The negative instructions remove predictable unwanted content.

Positive-Only Version

Prompt
Return exactly five Java interview questions with short answers.

Negative-Heavy Version

Prompt
Do not return more than five questions.
Do not return fewer than five questions.
Do not give long answers.
Do not include explanations outside the answers.
Do not include unrelated content.

The positive-only version is cleaner because it directly defines the target.

Use positive instructions for the main output and negative instructions for specific risks, exceptions, or known unwanted behaviours.

Negative Prompts for Text Generation

Text generation includes articles, summaries, emails, reports, descriptions, tutorials, social posts, and other written content.

Negative prompts can control:

  • Tone
  • Vocabulary
  • Length
  • Repetition
  • Claims
  • Structure
  • Audience level
  • Sensitive information
  • Promotional wording
  • Unwanted sections
  • Unsupported conclusions

Article Writing Example

Prompt
Write a beginner-friendly article explaining REST APIs.
Use simple language and practical examples.
Do not assume prior web-development knowledge.
Do not use unexplained abbreviations.
Do not compare REST with every other API style.
Do not include code longer than 15 lines.
Do not repeat the same explanation in multiple sections.

Expected Result

The output should:

  • Explain REST APIs at beginner level.
  • Define important terms.
  • Use short code examples.
  • Avoid unnecessary comparisons.
  • Avoid repeated definitions.

Summary Example

Prompt
Summarise the supplied project document in 200 words.
Include the objective, current status, major risks, and next action.
Do not add information that is absent from the document.
Do not guess dates or owners.
Do not present assumptions as confirmed facts.

This prompt protects the summary from hallucinated details.

Email Example

Prompt
Write a professional email requesting an update on the delayed deployment.
Keep the tone respectful and direct.
Do not blame any individual.
Do not use aggressive language.
Do not threaten escalation.
Do not include technical details unrelated to the delay.

Product Description Example

Prompt
Write a 100-word product description for a reusable water bottle.
Focus on material, capacity, cleaning, and daily use.
Do not use words such as revolutionary, perfect, guaranteed, or life-changing.
Do not make health claims.
Do not invent certifications.

SEO Content Example

Prompt
Write an SEO-friendly introduction for a Java interview preparation page.
Include the phrase Java interview questions naturally.
Do not repeat the target phrase more than twice.
Do not add keyword lists.
Do not use misleading claims such as guaranteed job selection.
Do not copy common competitor wording.

Text Classification Example

Prompt
Classify each review as Positive, Negative, or Neutral.
Do not explain the classification.
Do not rewrite the review.
Do not add categories outside the allowed labels.
Return one label per line in the original order.

Data Extraction Example

Prompt
Extract the invoice number, invoice date, vendor name, subtotal, tax, and total.
Do not infer missing values.
Do not calculate a missing total.
Use null when a field is not present.
Return valid JSON only.

Common Text-Generation Mistakes

  • Writing exclusions that are too broad
  • Repeating the same restriction in different words
  • Prohibiting content without defining the desired replacement
  • Asking for creativity while banning all variation
  • Using subjective rules such as “do not sound bad”
  • Mixing audience, tone, format, and content rules in one sentence
  • Forgetting to define output length
  • Creating exclusions that conflict with the main task

Negative Prompts for Code Generation

Negative prompts for code generation define technologies, methods, coding patterns, dependencies, security practices, or modifications that must be avoided.

They are useful when:

  • A project has a fixed technology stack.
  • Certain libraries are prohibited.
  • Deprecated APIs must be avoided.
  • Existing interfaces must remain unchanged.
  • Security-sensitive code must not expose secrets.
  • Only a specific file or method should be modified.
  • Generated code must remain compatible with a target version.
  • The model tends to over-engineer simple requirements.

Java Code Generation Example

Prompt
Create a Java 21 service that validates customer registration data.
Use records for the request model.
Use Jakarta Bean Validation annotations.
Do not use Lombok.
Do not use field injection.
Do not use deprecated Java APIs.
Do not include database code.
Do not place validation logic inside the controller.

Spring Boot Example

Prompt
Create a Spring Boot 3 REST controller for product search.
Use constructor injection.
Return ResponseEntity objects.
Do not use @Autowired on fields.
Do not expose entity objects directly.
Do not catch Exception as a generic fallback.
Do not include authentication code.

JavaScript Example

Prompt
Create a searchable HTML table using plain JavaScript.
Do not use jQuery.
Do not use external packages.
Do not reload the page during filtering.
Do not modify the original data array.
Do not place JavaScript inside HTML event attributes.

Python Example

Prompt
Create a Python function that reads a CSV file and returns valid records.
Use the standard csv module.
Do not use pandas.
Do not ignore malformed rows silently.
Do not use global variables.
Do not print inside the function.
Return validation errors separately.

SQL Example

Prompt
Write a parameterised SQL query that returns active customers created after a supplied date.
Do not use SELECT *.
Do not concatenate user input into the query.
Do not return password hashes or authentication tokens.
Do not use database-specific functions.
Sort the result by created_at in descending order.

Code Review Example

Prompt
Review the following method for correctness and performance.
Do not rewrite unrelated methods.
Do not rename public methods.
Do not change the returned data structure.
Do not introduce a new framework.
Do not suggest style changes unless they affect readability or maintainability.
Provide the smallest safe correction.

Refactoring Example

Prompt
Refactor the calculateInvoiceTotal method.
Preserve its public signature.
Preserve existing rounding behaviour.
Do not change other classes.
Do not add external dependencies.
Do not convert the method to asynchronous execution.
Add tests for the corrected logic.

Security Example

Prompt
Generate a login endpoint example.
Use password hashing and parameterised database access.
Do not store plain-text passwords.
Do not log passwords, access tokens, or session identifiers.
Do not return internal exception details.
Do not hard-code credentials.
Do not disable input validation.

Code Snippet

Prompt
// Main task
Create a Java method that removes duplicate integers while preserving insertion order.
// Required implementation
Use LinkedHashSet.
Return a new List<Integer>.
// Negative constraints
Do not modify the input list.
Do not use parallel streams.
Do not return null.
Do not use third-party libraries.
// Output requirement
Return only the method and a short usage example.

Why Positive Alternatives Matter in Code Prompts

Consider this instruction:

Prompt
Do not use an inefficient collection.

The term “inefficient” depends on the use case. It does not tell the model which collection is required.

A better instruction is:

Prompt
Use HashMap for constant-time key lookup.
Do not scan a List for every lookup.

The positive rule defines the required structure, while the negative rule blocks a known inefficient pattern.

Protecting Existing Code

When asking an AI model to modify code, define protected areas.

Prompt
Fix the null-handling bug in validateOrder.
Modify only the validateOrder method.
Do not rename classes, methods, variables, or fields.
Do not change the public API.
Do not change database queries.
Preserve all existing comments.
Return the complete updated method.

These instructions reduce unnecessary changes, but the result should still be reviewed and tested.

Negative Prompts for Image Generation

Negative prompting is widely used in image generation to describe visual elements that should not appear.

Some image-generation tools provide a separate negative prompt field. Other tools accept only one natural-language description. In that case, exclusions can be included in the main prompt.

Negative image prompts may control:

  • Unwanted objects
  • Incorrect anatomy
  • Extra fingers or limbs
  • Blurry details
  • Text or watermarks
  • Background clutter
  • Lighting problems
  • Camera angle
  • Visual style
  • Colour choices
  • Image defects
  • Cropped subjects
  • Duplicate objects
  • Distorted faces
  • Low-resolution appearance

Basic Example

Positive description:

Prompt
A professional software engineer working at a clean modern desk, realistic photography, natural daylight, medium-wide composition.

Negative exclusions:

Prompt
No visible brand logos.
No text overlays.
No watermark.
No extra computer screens.
No distorted hands.
No blurred face.
No cluttered background.

Product Image Example

Prompt
Create a studio product image of a stainless-steel water bottle on a plain light background.
Show the complete bottle.
Use soft and even lighting.
Do not include people.
Do not include text, logos, labels, or watermarks.
Do not crop the bottle.
Do not add extra objects.
Avoid strong reflections and distorted proportions.

Educational Illustration Example

Prompt
Create a clean educational illustration showing a user prompt entering an AI model and a response coming out.
Use simple arrows and clearly separated components.
Do not include company logos.
Do not include decorative background objects.
Do not use unreadable text.
Do not use dark or low-contrast labels.
Do not make the diagram look photorealistic.

Portrait Example

Prompt
Create a professional head-and-shoulders portrait with natural lighting and a neutral office background.
Keep the face sharp and realistic.
Do not crop the top of the head.
Do not add jewellery.
Do not add dramatic cinematic lighting.
Do not blur the eyes.
Do not distort facial features.

Negative Prompt Field Example

Some tools allow the desired description and exclusions to be separated.

Positive prompt:

Prompt
A peaceful mountain lake at sunrise, realistic landscape photography, clear reflections, wide composition, natural colours.

Negative prompt:

Prompt
People, buildings, boats, text, watermark, heavy fog, oversaturated colours, blurred details, distorted reflections, artificial lighting.

The exact effect of a negative prompt depends on the image model and interface. A term that works well in one model may have a weaker effect in another.

Avoid Long Keyword Dumps

A weak negative image prompt may contain a large collection of unrelated words:

Prompt
Bad, ugly, poor, low quality, strange, wrong, deformed, messy, terrible, imperfect, abnormal.

These terms are vague and may not clearly guide the model.

Use specific visual exclusions:

Prompt
No extra fingers.
No duplicated objects.
No blurred facial features.
No text or watermark.
No cropped hands.
No background clutter.

Describe the Desired Alternative

Instead of only writing:

Prompt
No dark background.

Use:

Prompt
Use a plain light-grey background.
Avoid dark or patterned backgrounds.

Instead of:

Prompt
No close-up.

Use:

Prompt
Use a medium-wide composition showing the subject from the waist up.
Do not use an extreme close-up.

The positive description gives the image model a clearer composition target.

Avoiding Excessive Negative Instructions

Too many negative instructions can weaken a prompt rather than improve it.

A large restriction list creates several problems:

  • The main objective becomes difficult to identify.
  • Important rules are hidden among minor rules.
  • Some restrictions may overlap.
  • The model may focus too much on prohibited terms.
  • The prompt may contain accidental conflicts.
  • The desired alternative may remain unclear.
  • The user may find the prompt difficult to maintain.
  • Output validation becomes complicated.

Excessive Negative Prompt

Prompt
Write an article about Java collections.
Do not make it long.
Do not make it short.
Do not use hard words.
Do not oversimplify.
Do not add too many examples.
Do not add too few examples.
Do not discuss every interface.
Do not miss important interfaces.
Do not repeat anything.
Do not use tables too much.
Do not avoid tables completely.

This prompt contains vague and conflicting rules.

Improved Prompt

Prompt
Write a 1,200-word beginner-friendly article about Java collections.
Explain List, Set, Queue, and Map.
Include one practical example for each interface.
Use a single comparison table.
Define technical terms in simple language.
Exclude concurrent collections and internal implementation details.

The improved version uses measurable positive requirements and only two focused exclusions.

How to Reduce Negative Instructions

  1. Group related exclusions.
  2. Remove repeated restrictions.
  3. Replace subjective rules with measurable requirements.
  4. Convert important negative rules into positive targets.
  5. Keep only exclusions linked to likely failure cases.
  6. Move low-priority rules into a validation checklist.
  7. Remove rules already made unnecessary by the output format.

Before Simplification

Prompt
Do not use paragraphs longer than necessary.
Do not write long sentences.
Do not use difficult words.
Do not use complex explanations.
Do not assume expert knowledge.
Do not include advanced details.

After Simplification

Prompt
Write for beginners.
Use sentences under 20 words where practical.
Define technical terms in plain language.
Limit the scope to basic concepts.

Prioritising Negative Rules

Not every exclusion has equal importance. Classify them as:

PriorityMeaningExample
CriticalMust never be violatedDo not expose passwords or API keys
HighDirectly affects correctnessDo not invent missing values
MediumAffects quality or styleDo not repeat the introduction
LowOptional preferenceAvoid using more than one table

Critical exclusions should be placed near the main task or under a clearly labelled constraints section.

Conflicting Negative Constraints

Conflicting constraints occur when two or more instructions cannot be followed together or create unclear behaviour.

Direct Conflict

Prompt
Explain every technical term.
Do not include definitions.

The model cannot fully satisfy both instructions.

Length Conflict

Prompt
Provide a complete technical explanation.
Keep the response under 50 words.
Do not omit any important detail.

The requested depth is unlikely to fit within the length limit.

Format Conflict

Prompt
Return valid JSON only.
Add a Markdown heading before the JSON.
Do not include text outside the JSON.

The heading requirement conflicts with the JSON-only rule.

Content Conflict

Prompt
Write an objective product comparison.
Do not mention any disadvantages.
Do not include promotional language.

A fair comparison normally requires strengths and weaknesses. Removing all disadvantages may make the result biased.

Code Conflict

Prompt
Use only the Java standard library.
Use the Apache Commons StringUtils class.
Do not add external dependencies.

Apache Commons is an external dependency, so the rules conflict.

Image Conflict

Prompt
Create a dark cinematic night scene.
Do not use dark colours.
Do not use artificial lighting.
Make every detail brightly visible.

These instructions create incompatible visual goals.

How to Resolve Conflicts

  1. Identify the primary objective.
  2. Mark the highest-priority requirement.
  3. Remove lower-priority rules that block the objective.
  4. Replace vague restrictions with measurable requirements.
  5. Separate mandatory rules from preferences.
  6. Define what should happen when a conflict remains.
  7. Add a fallback instruction.

Conflict-Resolution Example

Original prompt:

Prompt
Write a complete tutorial about Docker in 200 words.
Do not omit any Docker concept.
Do not use technical terms.

Improved prompt:

Prompt
Write a 200-word beginner introduction to Docker.
Explain containers, images, Dockerfiles, and registries.
Use simple technical terms and define each one briefly.
Exclude orchestration, networking internals, and production deployment.

The improved prompt narrows the scope instead of demanding complete coverage.

Priority-Based Prompt

Prompt
Primary task: Generate a valid JSON response matching the supplied schema.
Critical rule: Do not include text outside the JSON.
Secondary preference: Keep descriptions concise.
Conflict rule: If conciseness conflicts with schema validity, preserve schema validity.

Fallback Instruction

Prompt
If any negative constraint conflicts with the required output format, follow the required output format and state the conflict only when explanatory text is allowed.

Fallback instructions are valuable when complex prompts contain many constraints.

Replacing Negative Rules with Positive Rules

Negative rules explain what not to do. Positive rules define the desired alternative.

Replacing negative instructions with positive instructions often makes prompts:

  • Shorter
  • Clearer
  • Easier to follow
  • Easier to validate
  • Less contradictory
  • More focused on the desired result

Conversion Examples

Negative rulePositive replacement
Do not write a long answerLimit the answer to 200 words
Do not use complex languageUse beginner-friendly language
Do not use large paragraphsUse paragraphs of two to four sentences
Do not return XMLReturn valid JSON
Do not use field injectionUse constructor injection
Do not use old Java featuresUse Java 21-compatible APIs
Do not write unrelated informationCover only the listed topics
Do not repeat contentExplain each concept once
Do not include personal dataReplace personal details with anonymous labels
Do not guess missing valuesUse null for missing values
Do not create a close-up imageUse a medium-wide composition
Do not use a dark backgroundUse a plain light-grey background

Negative-Only Prompt

Prompt
Do not write long paragraphs.
Do not use difficult words.
Do not include advanced concepts.
Do not add unnecessary examples.
Do not repeat definitions.

Positive-First Prompt

Prompt
Write for beginners.
Use short paragraphs and plain language.
Explain only the fundamental concepts.
Include one practical example per concept.
Explain each definition once.

The positive-first version gives the model a clear target.

When Negative Rules Should Be Retained

Some negative instructions should remain explicit because the risk is important.

Examples:

Prompt
Do not expose API keys.
Do not store passwords in plain text.
Do not invent source data.
Do not modify the public API.
Do not include personal identifiers.
Do not use deprecated security algorithms.

These rules protect correctness, privacy, security, and compatibility.

Combined Conversion Method

Use this four-step method:

  1. Write the negative rule.
  2. Ask what the desired alternative is.
  3. Replace the rule with a positive requirement.
  4. Keep the negative rule only when it protects against a serious or common failure.

Example:

Negative rule:

Prompt
Do not use an unordered collection.

Desired alternative:

Prompt
Preserve insertion order.

Combined instruction:

Prompt
Use LinkedHashSet to preserve insertion order.
Do not use HashSet.

The positive rule defines the goal. The negative rule blocks the most likely wrong implementation.

Negative Prompt Examples

Example 1: Beginner Tutorial

Prompt
Task: Explain dependency injection in Java.
Audience: Beginner Java developers.
Required content: Definition, purpose, constructor injection, and one practical example.
Exclusions: Do not assume Spring knowledge.
Exclusions: Do not cover advanced dependency-injection containers.
Exclusions: Do not use unexplained design-pattern terminology.
Output: Use short sections and keep the response under 800 words.

Why It Works

  • The task is clearly defined.
  • The audience level is known.
  • The scope is limited.
  • Advanced content is excluded.
  • The output length is measurable.

Example 2: Technical Summary

Prompt
Summarise the supplied system-design document.
Include architecture, components, data flow, dependencies, risks, and unresolved decisions.
Do not add components that are absent from the document.
Do not treat proposed decisions as approved decisions.
Do not guess performance numbers.
Mark missing information as Not specified.
Return the summary using the requested headings.

Why It Works

The prompt prevents the model from converting uncertain or missing information into confirmed facts.

Example 3: Java Code Generation

Prompt
Create a Java 21 method that groups employees by department.
Use the Stream API.
Return Map<String, List<Employee>>.
Preserve employees in their original order.
Do not mutate the input list.
Do not use parallelStream.
Do not return null.
Do not use third-party libraries.
Return only the method and a five-line usage example.

Expected Code Characteristics

  • Java 21-compatible
  • Uses streams
  • Preserves input order
  • Does not change source data
  • Uses no external dependency
  • Contains no unrelated explanation

Example 4: SQL Query

Prompt
Write a parameterised SQL query that returns the ten highest-value completed orders from the last 30 days.
Return order_id, customer_id, total_amount, and completed_at.
Do not use SELECT *.
Do not include cancelled or pending orders.
Do not concatenate user input.
Do not return customer personal information.
Sort by total_amount in descending order.

Why It Works

The negative rules protect performance, security, privacy, and business correctness.

Example 5: Code Review

Prompt
Review the supplied Spring Boot service class.
Identify functional defects, transaction issues, security risks, and performance problems.
Do not rewrite the complete class.
Do not rename public methods.
Do not recommend a new framework.
Do not report formatting preferences as defects.
For each issue, include severity, reason, and smallest safe correction.

Why It Works

The prompt limits review scope and prevents unnecessary redesign.

Example 6: Content Rewriting

Prompt
Rewrite the supplied paragraph in professional business language.
Preserve all confirmed facts, dates, numbers, and names.
Do not add new claims.
Do not change the meaning.
Do not use emotional or promotional language.
Keep the rewritten version within 150 words.

Why It Works

The prompt protects factual meaning while changing style.

Example 7: Customer Support Response

Prompt
Write a helpful reply to a customer reporting a failed payment.
Acknowledge the issue and provide the next troubleshooting steps.
Do not blame the customer.
Do not promise a refund before verification.
Do not request passwords, PINs, or complete card details.
Do not claim the issue is resolved.
End with one clear action for the customer.

Why It Works

The exclusions protect security, accuracy, and customer experience.

Example 8: Data Extraction

Prompt
Extract product name, quantity, unit price, tax, and total from the supplied invoice text.
Do not calculate values that are missing.
Do not correct spelling inside product names.
Do not merge separate line items.
Use null for unavailable fields.
Return valid JSON only.
Do not include Markdown or explanatory text.

Why It Works

The output format and treatment of missing information are clearly defined.

Example 9: Image Generation

Prompt
Create a wide educational illustration of a prompt moving through an AI model and producing an answer.
Use a clean flat-design style.
Use simple icons and readable labels.
Do not include company logos.
Do not include watermarks.
Do not use a dark background.
Do not add decorative objects unrelated to the workflow.
Do not use small or distorted text.

Why It Works

The prompt defines the visual concept, desired style, composition, and excluded elements.

Example 10: Social Media Post

Prompt
Write a LinkedIn post introducing a free Java interview preparation tool.
Use a professional and helpful tone.
Mention MCQs, code-output questions, and revision support.
Do not claim guaranteed job placement.
Do not criticise other learning platforms.
Do not use more than three hashtags.
Do not use exaggerated marketing language.
Keep the post under 180 words.

Why It Works

The post remains promotional without becoming misleading or aggressive.

Example 11: API Response

Prompt
Generate a sample API response for successful user creation.
Return valid JSON.
Include id, name, email, status, and createdAt.
Do not include password, passwordHash, accessToken, refreshToken, or internal database fields.
Do not add comments.
Do not wrap the JSON in Markdown.

Why It Works

The exclusions prevent sensitive fields and formatting errors.

Example 12: Interview Questions

Prompt
Generate ten Java multithreading interview questions for developers with three years of experience.
Include a short expected answer after each question.
Do not include beginner syntax questions.
Do not include questions about frameworks.
Do not repeat the same concept using different wording.
Do not include trick questions with disputed answers.

Why It Works

The prompt controls experience level, scope, quality, and duplication.

Example 13: Bug Fix

Prompt
Fix the off-by-one error in the supplied pagination method.
Modify only the pagination calculation.
Do not change method names.
Do not change the response structure.
Do not add a new dependency.
Do not rewrite unrelated validation logic.
Include two tests covering the first and last page.

Why It Works

The model is given a narrow modification boundary and clear test requirements.

Negative Prompt Template

The following template can be reused for text, code, analysis, data extraction, and other AI tasks.

Prompt
Task:
[Describe the main task in one clear sentence.]
Context:
[Provide relevant background information.]
Input:
[Insert the content, data, code, or request to process.]
Required output:
[Describe exactly what the response must contain.]
Required behaviour:
[Describe how the model should perform the task.]
Negative content constraints:
Do not include [unwanted content].
Do not mention [excluded topic].
Do not invent [missing or unsupported information].
Negative behaviour constraints:
Do not [unwanted action].
Do not modify [protected content].
Do not assume [unconfirmed condition].
Technical exclusions:
Do not use [prohibited technology, library, API, or method].
Do not expose [sensitive data].
Format exclusions:
Do not include [unwanted formatting].
Do not add text before or after [required output].
Positive alternatives:
Use [preferred content, format, method, or style].
Replace missing information with [fallback value].
Priority:
[Identify the most important requirement.]
Conflict rule:
If two instructions conflict, follow [higher-priority instruction].
Validation:
Before returning the answer, check that the output contains no [excluded elements].

Negative Prompt Template for Text Generation

Prompt
Task:
Write [content type] about [topic].
Audience:
[Target audience]
Purpose:
[What the content should achieve]
Required content:
Include [required points].
Tone:
Use [desired tone].
Style:
Use [desired writing style].
Exclusions:
Do not include [unwanted topic].
Do not use [unwanted wording].
Do not make [unsupported claim type].
Do not repeat [content that should appear once].
Output:
Use [required structure].
Keep the response within [length].
Validation:
Confirm that every factual claim is supported by [source or input].

Negative Prompt Template for Code Generation

Java
Task:
Create [program, class, method, query, or component].
Technology:
Use [language, version, framework, and libraries].
Functional requirements:
[Requirement one]
[Requirement two]
[Requirement three]
Technical constraints:
Do not use [prohibited library].
Do not use [deprecated API].
Do not modify [protected interface or file].
Do not expose [sensitive information].
Do not hard-code [configuration or credentials].
Behaviour constraints:
Preserve [existing behaviour].
Handle [error or edge case].
Return [expected output].
Output requirements:
Return [code only, complete class, method, diff, or explanation].
Do not include [unwanted output].
Validation:
Check compatibility with [target version].
Check that no prohibited dependency is used.
Check that all required edge cases are handled.

Negative Prompt Template for Image Generation

Prompt
Subject:
[Describe the main subject.]
Environment:
[Describe the background and surroundings.]
Composition:
[Describe camera distance, angle, framing, and subject position.]
Style:
[Describe the visual style.]
Lighting:
[Describe the desired lighting.]
Required elements:
[List elements that must appear.]
Excluded objects:
No [unwanted object].
No [unwanted person or background element].
Visual exclusions:
No distorted anatomy.
No duplicated objects.
No blurred facial features.
No unreadable text.
No watermark.
No cropped subject.
Style exclusions:
Avoid [unwanted style].
Avoid [unwanted colour treatment].
Positive replacement:
Use [preferred alternative].
Output:
[Describe size, orientation, and quality.]

Negative Prompt Validation Checklist

Before using a negative prompt, check the following points:

  • Is the main task stated before the exclusions?
  • Is every negative instruction specific?
  • Can each instruction be checked in the final output?
  • Are subjective words replaced with measurable rules?
  • Does every important exclusion have a clear reason?
  • Are repeated exclusions removed?
  • Are positive alternatives provided where possible?
  • Do any instructions conflict?
  • Is the highest-priority requirement identified?
  • Is the output format clearly defined?
  • Are security and privacy exclusions explicit?
  • Are technical versions and compatibility requirements stated?
  • Is the list of exclusions short enough to understand?
  • Does the prompt define what to do with missing information?
  • Is there a fallback rule for unresolved conflicts?
  • Can the final output be validated against the restrictions?

Common Mistakes in Negative Prompting

Using Vague Exclusions

Weak:

Prompt
Do not include useless information.

Improved:

Prompt
Exclude historical background, unrelated frameworks, and repeated definitions.

Creating Too Many Restrictions

A prompt with twenty minor restrictions can hide the main objective. Keep only rules that affect correctness, safety, scope, or output quality.

Using Only Negative Instructions

Weak:

Prompt
Do not use jargon.
Do not write long paragraphs.
Do not use advanced examples.

Improved:

Prompt
Write for beginners.
Use short paragraphs.
Define each technical term.
Include one basic example.

Forgetting the Desired Alternative

Weak:

Prompt
Do not use XML.

Improved:

Prompt
Return valid JSON.
Do not include XML.

Adding Contradictory Rules

Weak:

Prompt
Explain the complete topic.
Do not include details.
Keep the answer under 50 words.

Improved:

Prompt
Provide a 50-word overview covering the definition and primary purpose only.

Excluding Required Content

A prompt may accidentally prohibit something necessary for task completion.

Example:

Prompt
Compare Java and Python.
Do not mention any differences.

The main task requires differences, so the exclusion makes the task impossible.

Using Unverifiable Language

Weak:

Prompt
Do not make the answer boring.

Improved:

Prompt
Use one practical example, short paragraphs, and active voice.

Treating Negative Prompts as Guaranteed Rules

AI output must still be checked. For high-risk tasks, use programmatic validation, testing, schema checks, security review, or human approval.

Best Practices

  • Start with a clear positive task.
  • Add negative instructions only for known risks.
  • Use one restriction per line.
  • Place critical exclusions near the main task.
  • Use measurable limits instead of subjective terms.
  • Provide the preferred alternative.
  • Separate content, behaviour, technical, and format exclusions.
  • Protect sensitive data explicitly.
  • Define how missing information should be handled.
  • State which rule has priority when constraints conflict.
  • Validate the final output.
  • Test the prompt with normal, unusual, and boundary inputs.
  • Revise exclusions based on actual model failures.
  • Remove restrictions that do not improve the result.

Final Example of a Complete Negative Prompt

Prompt
Role:
Act as a senior Java code reviewer.
Task:
Review the supplied Spring Boot service class.
Objective:
Identify correctness, security, transaction, performance, and maintainability problems.
Context:
The application uses Java 21, Spring Boot 3, Spring Data JPA, and PostgreSQL.
Required analysis:
Identify each issue.
Explain why it is a problem.
Assign Critical, High, Medium, or Low severity.
Suggest the smallest safe correction.
Required behaviour:
Base every finding on the supplied code.
Separate confirmed defects from possible risks.
Negative content constraints:
Do not invent missing classes or configuration.
Do not report personal style preferences as defects.
Do not repeat the same issue under multiple headings.
Negative behaviour constraints:
Do not rewrite the complete application.
Do not change public API contracts.
Do not rename public methods.
Do not change business rules unless they contain a confirmed defect.
Technical exclusions:
Do not introduce a new framework.
Do not use deprecated Spring APIs.
Do not suggest field injection.
Do not recommend disabling validation or security controls.
Security constraints:
Do not expose passwords, secrets, tokens, or private customer data.
Output format:
Return a table with Issue, Severity, Location, Reason, and Recommended Fix.
Add a corrected code snippet only when a code change is required.
Do not include unrelated explanations before the table.
Priority:
Preserve functional correctness and security above style preferences.
Conflict rule:
If a readability improvement changes public behaviour, preserve the existing public behaviour.
Validation:
Check that every issue points to a specific part of the supplied code.
Check that no prohibited framework or API is recommended.
Check that no secret or personal information is repeated.

Conclusion

Negative prompting helps control unwanted AI output by defining content, behaviour, formats, methods, and visual elements that should be avoided.

Its main purpose is not to create a long list of prohibitions. Its purpose is to remove specific and predictable failure patterns.

Effective negative prompting follows a balanced approach:

  • Clearly define the desired result.
  • Use positive instructions for primary requirements.
  • Add negative instructions for important exclusions.
  • Replace vague rules with measurable constraints.
  • Remove duplicate and conflicting restrictions.
  • Provide preferred alternatives.
  • Validate the final output.

A strong prompt tells the model both where to go and which specific paths to avoid. When positive and negative instructions are balanced correctly, the output becomes more focused, accurate, safe, and consistent.

Frequently Asked Questions

What is negative prompting?

Negative prompting is a technique where you explicitly tell an AI model what to avoid - unwanted content, behaviour, style, format, or technology - alongside the desired result, to reduce irrelevant, repetitive, unsafe, or incorrectly formatted output.

How is negative prompting different from positive instructions?

A positive instruction defines what the model should do and gives it a direct target, such as "use constructor injection." A negative instruction defines what to avoid, such as "do not use field injection." Positive instructions are usually easier to follow and verify.

When is negative prompting most useful?

Negative prompting helps when a model repeatedly includes unwanted information, a specific style or technology must be avoided, sensitive data must be excluded, or the response must not contain extra explanations, headings, or deprecated methods.

What's the difference between unwanted content and unwanted behaviour?

Unwanted content is information, wording, or elements that should not appear in the output, such as pricing details or competitor names. Unwanted behaviour is an action or response pattern to avoid, such as guessing missing facts or rewriting an entire class instead of one method.

Why can too many negative instructions hurt a prompt?

A long restriction list can hide the main objective, contain overlapping or contradictory rules, and make the model focus too much on prohibited terms. Grouping related exclusions and converting important ones into positive requirements usually produces a clearer, shorter prompt.

How do negative prompts work for image generation?

Some image tools provide a separate negative-prompt field for excluded visual elements like watermarks, distorted anatomy, or cluttered backgrounds; others require exclusions inside the main description. Specific visual exclusions work better than vague keyword dumps like "bad, ugly, low quality."

What causes negative constraints to conflict, and how can conflicts be resolved?

Conflicts happen when instructions cannot all be satisfied together, such as requiring a complete explanation while banning all definitions. Resolve conflicts by identifying the primary objective, marking the highest-priority rule, and adding an explicit conflict-resolution or fallback instruction.

Should every negative rule be converted to a positive rule?

Not always. Converting most negative rules to positive ones (e.g. "do not write a long answer" becomes "limit the answer to 200 words") makes prompts clearer, but critical rules protecting security, privacy, or correctness - such as "do not expose API keys" - should stay explicit.

What are common mistakes in negative prompting?

Common mistakes include vague exclusions like "do not include bad content," relying only on negative rules with no positive target, contradictory restrictions, and accidentally excluding content the task actually requires, such as banning "differences" in a comparison task.

Does negative prompting guarantee the model will never produce excluded content?

No. Negative prompting reduces the likelihood of unwanted output, but AI models generate statistically likely responses rather than following strict programming rules. For high-risk tasks, negative instructions should be combined with output validation, testing, or human review.