Prompt Design Guide for Large Language Model Applications
This guide presents a reusable framework for designing prompts in large language model (LLM) applications. It explains why ad-hoc prompts fail in production and then covers six core dimensions: role definition, instruction layering, tool descriptions, agent instructions, output formatting, and evaluation. You will learn how to structure prompts into a maintainable "prompt stack," reduce hallucinations and incorrect tool calls, enforce machine-parseable output, and iterate with data instead of guesswork. Platform-specific details should be verified against the official documentation of the platform you use.
1. Why You Need a Prompt Design Guide
When teams integrate LLM capabilities into real business workflows, a common pattern appears: the same model performs very differently depending on who wrote the prompt. Some prompts are stable, reusable, and easy to maintain. Others are full of vague wording, produce inconsistent output, and never make it into production. The root cause is usually not the model itself, but the lack of engineering discipline in prompt design.
A prompt is essentially a language for constraining model behavior and describing tasks. It is neither casual natural-language prose nor a traditional configuration file. It sits somewhere in between: an “executable specification.” As applications move from single-turn question answering to tool calling, multi-step tasks, and agent orchestration, prompts quickly grow into a “prompt stack” containing system instructions, role definitions, tool descriptions, output format constraints, and fallback strategies. Without a unified convention, maintenance costs rise sharply.
The goal of this guide is not to list tricks, but to provide a reusable design framework that helps developers build stable, testable, and iterable prompt systems on top of general-purpose LLM capabilities. For specific interfaces, quotas, and billing details, refer to the official model documentation of the platform you are using. This article focuses on general design methods.
2. Role Definition: Put the Model in the Right Problem-Solving Identity
Role definition is the first layer of a prompt. Its purpose is not “acting,” but activating the knowledge distribution and reasoning approach inside the model that match the task. A senior backend engineer investigating a performance issue focuses on very different things, and expresses them very differently, than a technical writer describing the same system.
An effective role definition includes three elements: identity, capability boundaries, and focus areas. For example:
You are a senior backend engineer familiar with distributed systems and database tuning.Your task is to analyze the given logs and identify potential performance bottlenecks.Prioritize three categories of issues: lock contention, slow queries, and resource saturation.Do not speculate about system parameters that were not provided.
The key is the last line: explicitly stating “what not to do” often reduces hallucinations more effectively than piling on “what to do.” Avoid vague adjectives in role definitions, such as “you are the best expert in the world.” Such phrasing places little constraint on model behavior.
3. Instruction Layering: Break Complex Tasks into Verifiable Steps
Most failures on complex tasks come from mixed instructions. Cramming “analyze the data, draw conclusions, and produce a report” into a single paragraph makes it easy for the model to lose track. A more reliable approach is to layer the instructions:
- Global constraint layer: define the overall goal, prohibited actions, and language and format requirements.
- Task decomposition layer: break the goal into ordered steps, each with clear inputs and outputs.
- Local prompt layer: provide specific instructions and examples for each step.
- Fallback layer: specify how to handle missing information, conflicts, or out-of-scope requests.
An example structure:
[GLOBAL] Answer in Chinese, lead with the conclusion, do not fabricate data.[STEP 1] Extract the key metrics from the material and list them in a table.[STEP 2] Based on the table, identify anomalies and provide the reasoning.[STEP 3] Output three actionable recommendations, ordered by priority.[FALLBACK] If the material lacks required fields, list the missing items first and stop inferring.
The benefit of layering is locatability: when output goes wrong, you can quickly tell whether the global constraints were unclear or one step was underspecified, instead of rewriting everything.
4. Tool Descriptions: Make the Model Understand Capability Boundaries
When an application introduces external capabilities, the quality of tool descriptions directly determines call accuracy. A tool description is not a comment for humans; it is the basis on which the model makes selection decisions. A common mistake is writing descriptions that are too brief, such as “query data,” leaving the model unable to tell when to use the tool or how it differs from neighboring tools.
A complete tool description should answer four questions: what the tool does, what the input is, what the output is, and when the tool should not be used. For example:
Tool: Order Status LookupPurpose: Return the current status and last update time for a given order ID.Input: order_id (string, required).Output: status, updated_at.Not applicable: batch aggregation, refund operations, historical trend analysis.
The “not applicable” section is often ignored, yet it significantly reduces incorrect calls. In addition, keep parameter naming semantically consistent and avoid mixing synonymous parameter names. For enumerated values, list the allowed range explicitly to reduce guesswork by the model.
5. Agent Instructions: Balance Autonomy and Control
The core tension in agent tasks is this: the model must plan autonomously, yet must not go off track. The solution is “clear goals, clear boundaries, and traceable process.”
- Clear goals: state the final deliverable in one sentence; avoid open-ended phrasing.
- Clear boundaries: define the scope of accessible information, the types of actions allowed, and the maximum number of steps.
- Traceable process: require the model to output a brief rationale at key steps so humans can review it.
Example:
Goal: Produce a competitor feature comparison summary of no more than five items.Constraint: Base it only on the material I provide; do not search the web for more.Step limit: four steps.For each step, use one line to state what you did and what it was based on.If the material is insufficient, output "insufficient information" and list the gaps.
Step limits and traceability are common means of controlling cost and observability. More autonomy is not always better; it should match the risk of the task. The higher the risk, the more the autonomy space should be reduced.
6. Output Format: Treat “Parseable” as a Hard Constraint
If a prompt targets program consumption, the output format must be treated as a hard constraint, not a suggestion. Common practices include: specifying field names and order, providing positive and negative examples, and defining how empty values and exceptions are expressed.
Output JSON only, with no additional explanation.Fields: {"summary": string, "risks": string[], "score": number}score must be an integer from 0 to 100.When there are no risks, return an empty array for risks.
It is important to note that format constraints must work together with business validation: after the model produces output, the output still needs parsing and field validation. Do not assume a prompt can guarantee correct structure 100% of the time. Treating the prompt as the “first constraint” and code validation as the “second line of defense” is a more robust engineering practice.
7. Prompt Stack Management: From One-Off Text to Maintainable Assets
As the number of prompts grows, you must manage them like code: versioned, modular, and testable. Split prompts into reusable fragments, such as role fragments, format fragments, and fallback fragments, and compose them into the final instruction. Keep a change note for every modification to avoid “change one line, break everything.”
Also build a small regression test set: select typical inputs and expected output characteristics, and verify quickly after each adjustment. Prompt iteration without evaluation is essentially blind editing.
8. Evaluation and Iteration: Use Data Instead of Intuition
Evaluation should cover three types of metrics: correctness (whether conclusions match the material), stability (whether similar inputs produce consistent outputs), and cost (whether the number of steps and context length stay under control). Start with manual sampling and annotation, then gradually accumulate automated test cases.
During iteration, follow the “single-variable principle”: change only one dimension at a time and observe the impact. If you adjust the role, format, and steps all at once, it is hard to tell where the gains came from.
9. Common Pitfalls
- Piling adjectives into the role definition without behavioral constraints.
- Writing long, unlayered instructions so the model cannot grasp the key points.
- Omitting “not applicable” scenarios in tool descriptions, leading to incorrect calls.
- Specifying format requirements without validating the output.
- Having no evaluation and no versioning, so prompts gradually spiral out of control.
10. Conclusion
Prompt design is an engineering skill, not a writing technique. Building conventions around six dimensions—role, layering, tools, agents, format, and evaluation—is what allows LLM capabilities to enter business workflows reliably. If you need to integrate cloud-based general capabilities, you can combine common categories such as object storage, message queues, container platforms, log services, and monitoring and alerting to build a complete application loop. For specific capabilities and limitations, refer to the official documentation of the platform you use.
