Prompt Engineering in Practice: Building a Structured, Scenario-Based Instruction System
This article explains why ad hoc prompts often produce inconsistent results and presents a practical method for turning validated instructions into maintainable assets. It covers the four-part role, background, constraints, and output-requirements structure; localization checks for Chinese-language prompts; scenario-based prompt libraries for office work, software development, marketing, and research; and practices for versioning, evaluating, and dynamically assembling prompts.
1. Why Prompts Are Often Poorly Written
Many people run into the same problems when using large language models. Instructions are vague, so the model’s answers drift in different directions. Business context is missing, so the model can only give generic answers. Templates found online are often written for foreign-language contexts; when used directly in Chinese scenarios, the sentences sound awkward and the format easily becomes inconsistent.
The common cause is the lack of a systematic way to write prompts. Every conversation starts from zero, and quality depends largely on luck. A more reliable approach is to turn validated instructions into templates, write them in a fixed structure, record results after use, and revise them step by step.
2. Four-Part Structure: Role, Background, Constraints, and Output Requirements
A common industry approach is the four-part structure of “role + background + constraints + output requirements.” It divides the information the model needs into four blocks, each answering one question: what identity the model should work under, what situation it faces, what it must not do, and what the result should look like. A clear structure often reduces randomness in model output, but results depend on the specific model and task and are not guaranteed to be good every time.
- Role setting: State the expert identity and area of experience, for example, “You are an engineer experienced in Python data analysis.”
- Background description: Explain the business environment and known conditions, such as data sources, field names, and data scale.
- Constraints: List boundaries, such as available libraries, prohibited practices, and standards that must be followed.
- Output requirements: Specify format, layout, and level of detail, for example, “Output runnable Python code with a brief explanation.”
Below is an example template for a data analysis scenario:
# RoleYou are a data analysis engineer experienced in Python, skilled at processing large-scale log data.# BackgroundThere is a CSV file of user behavior logs with columns user_id, timestamp, action_type, and page_id. It has about 5 million rows, and the runtime environment has 8 GB of memory.# Constraints1. The code must include exception handling and give clear messages when the file is missing or a field does not exist.2. Use chunked reading (chunksize) to process the data and avoid loading everything at once.3. Use only pandas and the Python standard library.# Output requirements1. Output complete Python code that counts page views (PV) and unique visitors (UV) for each page and sorts by PV in descending order.2. At the end of the code, explain the core logic in three sentences.
To make this template truly usable, runtime conditions also need to be recorded. The following information is recommended for each use:
- Model name and version. The same prompt can perform very differently across models.
- Key parameters. Code-generation tasks usually use a lower temperature (for example, 0 to 0.3) for more stable output; creative writing tasks can use a higher value. Specific values should follow the documentation of the platform in use.
- Validation method. First run the code on a small sample, manually check the PV and UV calculation results, and then run it on the full dataset.
The four-part structure is only one common approach. Reasoning-intensive tasks, such as complex algorithm design, may require the model to reason step by step; long-document processing should first describe the document structure and then ask the question. For such tasks, adjust the structure based on actual results.
3. Localization for Chinese-Language Contexts
Directly translating foreign-language prompts commonly causes three types of problems: the sentence patterns sound like translations and read awkwardly; terminology does not match local systems; and format requirements conflict with Chinese document conventions. When writing Chinese-language prompts, check each item in the following checklist.
| Check item | Key point | Example |
|---|---|---|
| Expression habits | Use short sentences and complete subjects; avoid long, complex foreign-style sentences | “Please give the conclusion first, then list the supporting evidence.” |
| Terminology consistency | Use one term for one concept and align it with industry standards | Use “user profile” consistently; do not mix it with “user tag.” |
| Compliance statement | For personal information, finance, healthcare, and similar fields, state applicable regulatory requirements | Require phone-number masking under applicable personal information protection regulations |
| Output format | Specify punctuation, date format, and the layout of official documents or reports | Write dates consistently as “November 20, 2026.” |
| Sensitive information | Remove ID numbers, phone numbers, and other private fields before input | Replace real data with placeholders |
| Human review | Legal, medical, and financial conclusions must be reviewed by professionals | Treat model conclusions as reference drafts only |
Major models with strong Chinese-language coverage often perform well on classical literature, local cultural knowledge, and local business processes. When writing prompts, local context can be written directly into the background section, for example, by stating that the target readers are operations staff in a Chinese-language environment or that the copy must fit local platform conventions. Which model is more suitable should be confirmed through comparative tests on the same task.
4. Building a Prompt Library by Business Scenario
Classifying prompts by “industry plus function” helps teams find and reuse existing templates. The four common scenarios below each include points to focus on when writing prompts. This classification is intended to organize thinking and cannot cover every need. Organizations should review their own business lists item by item.
4.1 Workplace and Office
The core of workplace scenarios is compressing text and extracting structured information. A meeting-minutes template can require the model to output four fields: decisions, action items, owners, and deadlines. For example:
Input: A 30-minute meeting transcript.
Output: A table with four columns: decisions, action items, owners, and deadlines. If the transcript does not mention an owner or deadline, write “Not specified”; do not infer it.
A status-report template can require the core conclusion first, followed by data support and an action plan, so leaders can quickly grasp the key points.
Failure case: If the template only says “help me organize the meeting minutes,” the model may omit action items or treat discussion content as decisions. Adding field definitions and a rule such as “leave blank if not specified” reduces omissions and misclassification.
4.2 Programming and R&D
In addition to code generation, R&D scenarios include three other common tasks.
Architecture design: Provide business requirements and require the model to output a technology comparison table, a system structure diagram (which can be represented with Mermaid code), and a database schema. The model should explain the assumptions behind each technology choice to support review.
Code review: Input existing code and require the model to evaluate it across security, performance, and maintainability, with each comment including the corresponding code location and a suggested change.
Test case generation: Specify the function name, parameter types, and boundary conditions, and require unit tests that cover the normal path, null values, and out-of-range values. Generated tests must be actually run and confirmed to pass, not merely checked for completeness.
4.3 Creative and Marketing
For marketing copy, the model can generate multiple style versions for the same product, such as rational analysis, emotional resonance, and pain-point amplification, which the team then uses for A/B testing. The prompt should specify the platform (for example, a lifestyle-focused social platform), word limit, number of titles, and whether emojis are allowed.
If the copy needs to be closer to users, first ask the model to analyze the target users’ concerns and motivations, and then generate copy based on the analysis. Executing the two steps separately is usually easier to check than doing everything in one step.
4.4 Academic Research
Literature review is one of the scenarios with the highest accuracy requirements. A prompt can ask the model to summarize research schools based on abstracts provided by the user and label each argument with the corresponding reference number. It should also explicitly prohibit fabricating data or references.
Model-generated citations and data still require manual verification. Reference numbers, authors, and years should be confirmed one by one in the original database and must not be written directly into a paper.
5. Treating Prompts as Maintainable Assets
Prompts still need ongoing management after they are written. Enterprise teams can store validated templates in an internal knowledge base and record the owner, version number, applicable model, evaluation set name, and latest evaluation result for each template. When a template changes, keep the old version for traceability.
Individual developers can build a local or cloud-based prompt library, tag prompts by scenario, and use variable substitution for dynamic assembly when calling large language model APIs. Example code:
PROMPT_TEMPLATE = """# RoleYou are a {role}.# Background{context}# Output requirements{output_requirement}"""prompt = PROMPT_TEMPLATE.format(role="senior backend engineer",context=user_input, # From user input; check length and filter sensitive fields before concatenationoutput_requirement="Output an API design document in Markdown format",)
User input may contain content that attempts to rewrite the instructions. Therefore, place it in a clearly delimited area and state in the constraints that instructions inside it must not be executed.
