0Pricing
AI Prompt Engineering · Lesson

Diagnosing and Fixing Bad Prompts

A systematic debugging checklist for improving underperforming prompts.

Diagnosing and Fixing Bad Prompts is a free AI Prompt Engineering lesson on CoddyKit — lesson 4 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the AI Prompt Engineering learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

The Debugging Mindset

When a prompt produces a bad output, most people's first instinct is to blame the model. But in most cases, the problem is in the prompt — and the model is behaving exactly as it should given the instructions it received.

Treating prompt failures as debugging problems is more productive. Just like debugging code, you systematically identify the root cause, hypothesize a fix, test it, and verify the result. This mindset produces faster improvement than frustrated trial and error.

The Prompt Debugging Checklist

When a prompt fails, work through this five-dimension checklist systematically:

  1. Specificity — Is it too vague? Does the task need more precise definition?
  2. Context — Is background information missing that the model needs?
  3. Format — Is the desired output format and length specified?
  4. Constraints — Are constraints clearly stated? Do any of them conflict?
  5. Examples — Would an example of good output eliminate ambiguity?

Each dimension maps to a specific type of fix. Identify which dimension failed and apply the corresponding fix.

Dimension 1: Specificity Check

Specificity failures produce: wrong topic, wrong angle, wrong audience level, missing key aspects of the task.

Diagnostic questions:

  • Could a smart stranger interpret this prompt differently than I intended?
  • Are there vague words (good, better, appropriate, professional) that need replacement?
  • Is the task type specified (article? email? summary? analysis?)?
  • Is the audience defined precisely enough?

Fix: Replace vague words with specific ones. Name the task type. Specify the audience background. Add a one-sentence example of the output you want.

Dimension 2: Context Check

Context failures produce: generic advice that ignores your specific situation, assumptions about your tech stack, company, or audience that are wrong, responses that would work in a different context but not yours.

Diagnostic questions:

  • What does the model need to know about my specific situation that it cannot know from general training?
  • Have I provided the relevant code, document, or data the task is about?
  • Have I described the constraints of my environment?

Fix: Add a Background section before the task instruction. Paste relevant code or content directly into the prompt.

Dimension 3: Format Check

Format failures produce: right content, wrong structure — prose when you needed bullets, an essay when you needed a step-by-step guide, no headers when navigation was needed.

Diagnostic questions:

  • Did I specify the output format (bullet points, numbered list, prose, table, code block)?
  • Did I specify the length?
  • Did I specify required sections or a structure?

Fix: Add explicit format instructions. Use the pattern: "Format: [structure]. Length: [target]. Sections: [list]." For complex formats, provide a template with placeholder text the model should fill in.

Dimension 4: Constraints Check

Constraint failures produce: content that includes what you wanted to exclude, or outputs that feel robotic because constraints conflict.

Diagnostic questions:

  • Are my constraints clearly stated or are they implied?
  • Do any constraints conflict with each other?
  • Do my constraints conflict with the content scope or length?
  • Is there a priority instruction for near-conflicting constraints?

Fix: Make implicit constraints explicit. Add a prioritization instruction. Resolve conflicts by choosing which constraint wins. Check that scope and length are compatible.

Dimension 5: Examples Check

When the first four dimensions look fine but output is still off, examples are often the missing piece. They communicate what words cannot.

Diagnostic questions:

  • Would showing an example of good output clarify the expected style, tone, or format?
  • Would a negative example (what NOT to produce) help?
  • Are there existing outputs from this task type you can use as a reference?

Fix: Add one or two examples of ideal output to the prompt. Use the pattern: "Here is an example of what I am looking for: [example]. Now do the same for [your actual task]."

A Prompt Debugging Workflow

Here is a complete diagnostic workflow you can apply to any failing prompt:

def diagnose_prompt(original_prompt, failed_output, problem_description):
    '''
    Use a second LLM call to diagnose why a prompt produced a bad output.
    Returns a diagnosis and an improved prompt.
    '''
    import openai
    client = openai.OpenAI(api_key='sk-...')

    diagnosis_prompt = f'''You are a prompt engineering expert.

A user ran this prompt:
---PROMPT---
{original_prompt}
---END PROMPT---

It produced this output (which was unsatisfactory):
---OUTPUT---
{failed_output[:500]}...
---END OUTPUT---

The problem the user identified: {problem_description}

Diagnose the prompt failure using this framework:
1. Specificity: Is anything too vague?
2. Context: What background information is missing?
3. Format: Is the desired format/length unclear?
4. Constraints: Are there missing or conflicting constraints?
5. Examples: Would an example help?

Then write an improved version of the prompt that addresses the root cause.
Format: Diagnosis: [analysis] || Improved prompt: [new prompt]'''

    response = client.chat.completions.create(
        model='gpt-4o-mini',
        messages=[{'role': 'user', 'content': diagnosis_prompt}]
    )
    return response.choices[0].message.content

Root Cause vs Symptom

A common debugging mistake is treating the symptom rather than the root cause.

Symptom: The output is too generic.

Symptom fix: Adding "be more specific" to the prompt.

Root cause: The audience was not defined, so the model defaulted to a generic audience.

Root cause fix: Adding a precise audience specification.

Treating symptoms produces marginal improvement. Treating root causes produces reliable improvement. Ask "why is this symptom happening?" one level deeper before writing the fix.

Keeping a Prompt Failure Log

For recurring task types, keeping a prompt failure log accelerates improvement over time. Each entry records:

  • The original prompt
  • The bad output (or description of what was wrong)
  • The diagnosed root cause (specificity / context / format / constraints / examples)
  • The fix applied
  • The result

After 10-20 entries, patterns emerge. You may find that the same root cause (e.g., missing audience context) accounts for 60% of failures in a category. Fix it in the template and the pattern disappears.

The Improved Prompt Template

Most well-structured prompts follow a consistent template that addresses all five debugging dimensions proactively:

ROBUST_PROMPT_TEMPLATE = '''
## Role
[Who the model should act as — establishes expertise level and perspective]

## Context
[Background the model needs: company, audience, product, prior decisions, constraints]

## Task
[Specific, precise description of what to produce]

## Format
[Output structure: bullet points / prose / numbered list / table]
[Length: word count or sentence count]
[Required sections: list them if the output needs specific sections]

## Constraints
[What to include: required elements]
[What to exclude: off-limits content or approaches]
[Priority: if constraints conflict, X takes priority over Y]

## Example
[One example of good output for this task type — optional but powerful]
'''

print(ROBUST_PROMPT_TEMPLATE)

Knowledge Check: Prompt Debugging

A prompt produces output that is well-written but focuses on general best practices for the topic rather than the specific situation described in the task. The format and length are correct. The constraints are not violated. Which debugging dimension is the root cause?

Recap: Diagnosing and Fixing Bad Prompts

Prompt debugging is a systematic process, not trial and error. The five-dimension checklist — Specificity, Context, Format, Constraints, Examples — maps every common failure type to a specific fix.

The robust prompt template addresses all five dimensions proactively, preventing most failures before they occur. The debugging workflow (identify symptom → find root cause → apply fix → verify) produces reliable improvement. A prompt failure log accelerates learning across sessions.

With these tools, you can diagnose and fix any prompt failure methodically and consistently.

Frequently asked questions

Is the “Diagnosing and Fixing Bad Prompts” lesson free?

Yes — the full text of “Diagnosing and Fixing Bad Prompts” is free to read here on the web, and the AI Prompt Engineering course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the AI Prompt Engineering course, upgrade to CoddyKit PRO.

What will I learn in “Diagnosing and Fixing Bad Prompts”?

A systematic debugging checklist for improving underperforming prompts. You practise AI Prompt Engineering with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start AI Prompt Engineering?

No prior experience is required. AI Prompt Engineering on CoddyKit is structured for beginners through advanced learners; this is — lesson 4 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “Diagnosing and Fixing Bad Prompts” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this AI Prompt Engineering lesson?

Yes. Every AI Prompt Engineering lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. Overly Vague Instructions
  2. Contradictory Requirements
  3. Missing Context Errors
  4. Diagnosing and Fixing Bad Prompts
← Back to AI Prompt Engineering