Lesson 3 of 4 Troubleshooting GenAI Applications

Troubleshooting and Maintaining Prompts

This lesson covers how to replace vague reports about prompt quality with tests and comparisons, and how prompt maintenance keeps prompts healthy as models, data and users change.

Learning outcomes

After completing this lesson, you will be able to:

  • Reproduce and measure prompt problems with tests and version comparison.
  • Apply standard fixes for common root causes.
  • Maintain prompts with template testing and observability.

Prompt testing frameworks and version comparison

When users report that a prompt has started producing poor answers, the first step is to reproduce and measure the problem rather than edit the prompt immediately. A prompt testing framework runs a prompt over a test set and reports pass rates for each requirement, such as format, required content, tone and refusals, which shows how widespread the problem is and which requirement is failing.

Version comparison then runs the same tests on the current and previous prompt versions, from Prompt Management or the template repository, and, if the model has changed, on the old and new models. Comparing the results shows whether the regression came from a prompt edit, a model change or a change in the inputs users are sending, which determines the fix.

Systematic refinement

Common root causes have standard fixes. Ambiguous or conflicting instructions are rewritten and prioritised. Instructions buried in long context are moved to the start and restated at the end. Missing examples for the desired format are added. Prompt confusion, where the model treats retrieved text or user input as instructions or answers the wrong question, is fixed with clear delimiters and explicit labels. Overloaded prompts that do several tasks are split into a chain. Each change is tested on the full suite before release as a new version.

The following diagram compares the prompt structure before and after the fix.

Fixing a prompt that answers the wrong question. Retrieved FAQ entries were formatted exactly like the user's question, so the model sometimes answered one of them. Wrapping retrieved content in reference tags, labelling the user's question in question tags and instructing the model to answer only that question fixes it.
Delimiters tell the model which text is data and which is the question.
Match the pairs

Prompt root causes

Exam skills 5.2.3

Match each prompt root cause with its standard fix.

Log in to try this activity Interactive activities are free with an account.

Prompt maintenance and observability

Template testing verifies that every variable is filled and that rendered prompts stay within token budgets, catching broken templates (for example an empty {{context}} because a retrieval call failed). CloudWatch Logs analysis of rendered prompts and responses, with Logs Insights, reveals confusion patterns such as frequent clarification requests or responses that quote instructions. X-Ray annotations recording the prompt template name and version on each trace create a prompt observability pipeline that links latency, errors and quality metrics to specific prompt versions. Schema validation of outputs detects format inconsistencies as soon as they start. A refinement workflow collects failures, proposes fixes, tests them and promotes new versions through Prompt Management. The following table summarises the tools.

ProblemDiagnosticTypical fix
Quality dropped after a changeVersion comparison on the test suiteRevert or refine the change
Model treats context as instructionsLogs Insights over rendered promptsDelimiters, labels, explicit rules
Format inconsistenciesSchema validation metricsSchema or tool use; examples; lower temperature
Empty or broken variablesTemplate testsValidate inputs before rendering
Which prompt version causes errors?X-Ray annotations by template and versionRoll back that version
Fix the problem

A broken template

Exam skills 5.2.5

Find the cause and fix of each prompt maintenance problem.

Log in to try this activity Interactive activities are free with an account.
Worked example

A prompt that answers the wrong question

After retrieved FAQ entries were added to a prompt, the assistant sometimes answers one of the FAQ questions instead of the user's question.

Logs Insights over rendered prompts shows FAQ entries formatted exactly like the user's question. The fix wraps retrieved content in <reference> tags, labels the user's question explicitly in <question> tags, adds an instruction to answer only the question, and validates the change against the test suite before promoting the new version.

Check yourself

What is the first step when a prompt problem is reported?

Show answer

Reproduce it with a test suite before changing anything.

Exam Tips

Remember for the exam

  • Reproduce prompt problems with a test suite before changing anything.
  • Compare prompt and model versions to find the source of a regression.
  • Prompt confusion: delimit and label context, input and instructions.
  • Annotate traces with prompt template and version; validate output schemas continuously.