Reliable prompt engineering for developers is less about finding a perfect sentence and more about designing a clear contract between an application and a language model. This checklist covers reusable patterns for structured output, extraction, classification, code generation, tool calling, validation, refusal handling, and multi-step workflows—plus a practical method for debugging prompts when behavior changes.
Overview
A production prompt should make five things clear: the task, the available context, the expected response, the constraints, and what to do when the request cannot be completed safely or accurately. Treat those elements as an interface rather than as casual instructions. The prompt is one part of the system; schemas, application-side validation, retries, logging, permissions, and evaluation are equally important.
A useful baseline separates stable instructions from variable input:
Role: You classify support requests for routing.
Task:
Assign exactly one category to the user message.
Allowed categories:
- billing
- technical_support
- account_access
- other
Output:
Return a JSON object with the keys "category" and "reason".
The category must be one of the allowed values.
The reason must be no longer than 20 words.
User message:
{{user_message}}
This pattern is easy to test because the expected categories, output keys, and length constraint are visible. If the model or provider supports structured-output features, use a schema in addition to the prompt. A schema can constrain the response format, while the prompt explains the task and the meaning of each field.
Prompt wording cannot replace application controls. Parse the response, validate it against the expected type and allowed values, and decide what happens when validation fails. For tool use, validate arguments and authorization in your application before executing any action. A model should be treated as an untrusted planner, not as the final permission layer.
Checklist by scenario
Extraction and structured output
- Define the fields the application actually needs; avoid asking for extra prose.
- Specify field types, allowed values, units, and whether a field may be null.
- State how missing, conflicting, or ambiguous information should be represented.
- Use a provider-supported schema when available, then validate the returned object in code.
- Keep raw input separate from instructions so user text cannot silently redefine the task.
For example, an invoice extractor should distinguish between a missing invoice date and an invoice date that cannot be parsed. Returning null with a reason is often more useful than inventing a value. Post-processing should also normalize dates, currencies, and whitespace according to your application's rules.
Classification
- List the complete label set and define boundaries between similar labels.
- Tell the model whether it must choose one label or may return several.
- Include representative examples for difficult or easily confused cases.
- Define an
unknown,other, orneeds_reviewpath when confidence is insufficient. - Evaluate on examples that were not copied into the prompt.
Examples are most valuable at decision boundaries. If “billing” and “account access” are often confused, show one example of each and explain the distinction briefly. Avoid adding a long collection of easy examples that increases prompt size without clarifying the classification rule.
Code generation
- State the language, runtime, framework version, input and output contracts, and relevant constraints.
- Provide a small representative input and the expected result.
- Ask for tests or test cases, not only implementation code.
- Specify security requirements such as input validation, secret handling, and safe error reporting.
- Require the model to identify assumptions rather than silently choosing them.
A practical code-generation prompt requests a minimal patch when modifying an existing project. Include the relevant file, the failing behavior, and the acceptance criteria. Asking for an explanation of every line can consume context without improving the implementation; request a short summary and focused tests instead.
Tool calling
- Describe each tool's purpose, required arguments, side effects, and failure conditions.
- Make read-only tools distinct from tools that create, update, delete, send, or purchase.
- Require confirmation before consequential actions unless the product's approved workflow explicitly permits automatic execution.
- Validate tool arguments against a schema and enforce authorization outside the model.
- Return clear tool errors so the model can recover without guessing.
A tool-calling workflow should be designed as a loop: decide whether a tool is needed, validate the proposed call, execute it if permitted, return a bounded result, and decide whether a final response is ready. Do not expose unnecessary credentials, unrestricted database access, or broad administrative functions simply because a model may be able to use them.
Validation and refusal handling
- Define what the model should do when required context is absent.
- Ask it to distinguish known information from an inference or recommendation.
- Provide a concise fallback such as “I need the document ID” or “I cannot complete that action.”
- Have the application detect empty, malformed, or unsupported responses.
- Log the reason for a fallback without storing sensitive content unnecessarily.
Good refusal handling is specific. Instead of asking the model to “be safe,” state the boundary and the next useful step. For example: “If the request requires a permission the current user does not have, do not call the tool. Explain that authorization is required and identify the correct support path.”
Multi-step workflows
- Break the workflow into named stages with a defined input and output for each stage.
- Persist important state in application data rather than relying on the model's memory.
- Set a maximum number of retries or tool iterations.
- Pass only the context needed for the current stage.
- Record intermediate decisions so failures can be reproduced.
For retrieval-augmented applications, separate retrieved evidence from the user's request and instruct the model to use the evidence only for the supported task. A useful next step is the production RAG application guide, which addresses APIs, evaluation, and cost controls.
Which control should you use?
| Control | Use it when | Do not rely on it alone when |
|---|---|---|
| Instructions | You need to define the task, priorities, or behavior. | A response must satisfy a machine-checked contract. |
| Examples | The task has subtle patterns or ambiguous categories. | The examples are stale, unrepresentative, or too numerous. |
| Schema | Your application requires typed, machine-readable output. | Business rules, permissions, or semantic correctness must be enforced. |
| Constraints | You need limits on length, labels, scope, or format. | The constraint is not also checked by application code. |
| Post-processing | You need normalization, validation, retries, or safe execution. | You are using it to conceal an unclear task definition. |
What to double-check
Before shipping a prompt, inspect the boundary between instructions and data. Delimit user-provided text, retrieved documents, and tool results clearly. Tell the model which sources are authoritative for the current task, and never assume that a quoted document has permission to change system behavior.
Check token and context limits for the specific model and API configuration you use. Large examples, conversation history, retrieved passages, and tool results all compete for context. Summarize or retrieve selectively, and measure the effect of truncation rather than assuming the model received the complete input.
Check structured-output behavior using both valid and invalid cases. A response can be valid JSON and still contain an unsupported category, an incorrect date, or an unsafe action. Validation should therefore cover syntax, types, allowed values, required fields, and business rules.
Finally, compare prompt changes with a small regression set. Include normal requests, ambiguous requests, missing information, adversarial wording, long inputs, tool failures, and refusal cases. Track quality alongside latency, token usage, tool-call errors, and fallback rates. The LLM application evaluation guide provides a useful framework for turning these checks into repeatable tests.
Common mistakes
- Overloading one prompt. A single instruction that classifies, searches, writes, edits, and executes actions is difficult to test. Split unrelated responsibilities into stages.
- Requesting JSON without validating it. Format instructions improve consistency but do not replace parsing, schema validation, or business-rule checks.
- Using vague quality words. “Be accurate” is weaker than defining the source of truth, required fields, acceptable uncertainty, and fallback behavior.
- Putting secrets or permissions in the prompt. Prompts are not an access-control mechanism. Keep credentials in the application and enforce authorization before execution.
- Adding examples without measuring them. Few-shot examples can clarify a task, but they can also bias classification or increase context costs. Test their contribution.
- Changing several variables at once. If the prompt, model, temperature, retrieval settings, and parser all change together, a regression becomes difficult to diagnose.
When to revisit
Revisit prompts whenever the workflow or its inputs change—not only when a model is replaced. Schedule a review before seasonal planning cycles, major product releases, or changes to data sources and tool permissions. Also review after repeated fallback errors, unexpected tool calls, a rise in malformed output, or a shift in user requests.
Provider APIs evolve. Before migrating a model or changing settings, verify the current documentation for structured-output support, tool-calling formats, context limits, tokenization, safety behavior, and retry guidance. Do not assume that a prompt written for one API uses the same message roles or response format elsewhere.
Use this short change checklist:
- Record the old prompt, model configuration, schema, and evaluation results.
- Run the same regression set against the proposed change.
- Inspect failures by scenario rather than relying only on an overall score.
- Review cost, latency, privacy, and tool-execution outcomes.
- Release gradually when the workflow has meaningful operational risk.
- Document the new assumptions and set the next review trigger.
For a final pre-release check, ask whether every important output is typed and validated, every consequential action is authorized outside the model, every refusal has a useful next step, and every known failure mode appears in the test set. That discipline makes prompt engineering a maintainable developer practice rather than a one-time wording exercise.