Skip to main content
Accuracy tuning

Text-to-text

Design effective prompts

Design effective prompts

Write clear, specific instructions

Vague prompts produce vague results. The more context and constraints you provide, the closer the output matches your expectations. Think of it like delegating a task: a one-line request leaves too much room for interpretation, while detailed instructions with clear goals produce exactly what you need.
Clear, specific prompts are the single most important factor in getting useful output from an LLM.
Example: Code generation task
Vague promptClear, specific prompt
Write a Python function to process data.Write a Python function that reads a CSV file, filters rows where the status column equals "active", and returns a list of dictionaries. Include type hints, handle the case where the file does not exist, and use the csv module from the standard library.
The specific prompt defines the input format, expected output, error handling, and library constraints -- enough for the model to produce usable code on the first try. Example: Content generation task
Vague promptClear, specific prompt
Help me write a product announcement.Write a 200-word product announcement for "Zephyr Z9", a lightweight portable phone by Bailian. Highlight its ultra-thin design, high-performance specs, and ease of use. Target tech-savvy consumers on social media. Keep the tone energetic and concise.

Structure prompts with a framework

A prompt framework helps you systematically provide the information an LLM needs. Instead of guessing what to include, use these six elements as a checklist:
Prompt framework diagram
ElementPurposeExample
ContextBackground information relevant to the task"You are reviewing pull requests for a Python microservice."
ObjectiveThe specific task to complete"Identify potential bugs and suggest fixes."
StyleWriting style or persona"Write as a senior backend engineer."
ToneEmotional quality of the output"Professional but constructive."
AudienceWho reads the output"Junior developers on the team."
ResponseDesired output format"A numbered list of issues with code suggestions."
Use # delimiters to mark each section in your prompt:
#Context#
You are reviewing pull requests for a Python microservice that handles
user authentication. The codebase uses FastAPI and SQLAlchemy.

#Objective#
Review the following code diff and identify potential security
vulnerabilities, performance issues, and style violations.

#Style#
Write as a senior backend engineer conducting a thorough code review.

#Tone#
Professional but constructive -- explain why each issue matters.

#Audience#
Junior developers who are learning secure coding practices.

#Response#
A numbered list of findings. For each finding, include:
- The specific line or code block
- Why it is a problem
- A suggested fix with code
Not every prompt needs all six elements. Adapt the framework to your task. The examples throughout this guide use different subsets depending on the scenario.

Optimize prompts

Provide output examples

Including examples of expected output helps the model match your format, style, and level of detail. This technique -- known as few-shot prompting -- also improves consistency across multiple runs. Example: Structured data extraction
#Context#
Extract structured information from user support tickets.

#Objective#
Parse each ticket into a JSON object.

#Examples#
Input: "My order #12345 arrived damaged. I want a refund."
Output:
{
  "order_id": "12345",
  "issue_type": "damaged_item",
  "requested_action": "refund"
}

Input: "I can't log in to my account. I've tried resetting my password
twice."
Output:
{
  "order_id": null,
  "issue_type": "login_failure",
  "requested_action": "account_recovery"
}

#Task#
Now parse this ticket:
Input: "Order #67890 has been stuck in 'processing' for 5 days.
Please expedite or cancel it."
The model learns the JSON schema, field naming conventions, and how to infer issue_type and requested_action from natural language -- all from the examples alone.

Break complex tasks into steps

For complex tasks, define explicit steps for the model to follow -- not just the desired result. Step-by-step instructions prevent the model from skipping intermediate reasoning. Example: Math word problem
#Context#
Timmy leaves home at 8:00 AM, walking at 50 meters per minute. After
12 minutes, his father notices Timmy forgot his homework and chases
him on a bicycle at 200 meters per minute. After catching up, the
father carries Timmy on the bicycle for the rest of the trip. The
bicycle distance is 5 times the walking distance.

#Objective#
Calculate the arrival time.

#Steps#
1. Calculate how far Timmy walks before his father catches up.
2. Determine how long it takes the father to catch up.
3. Calculate the remaining bicycle distance and travel time.
4. Add up all time intervals to find the arrival time.
Model output (following the steps):
Step 1: Timmy walks for 12 minutes before his father starts:
  12 min * 50 m/min = 600 m head start

Step 2: Father's relative speed: 200 - 50 = 150 m/min
  Catch-up time: 600 m / 150 m/min = 4 minutes
  Timmy walks an additional: 4 min * 50 m/min = 200 m
  Total walking distance: 600 + 200 = 800 m

Step 3: Bicycle distance: 800 m * 5 = 4,000 m
  Bicycle time: 4,000 m / 200 m/min = 20 minutes

Step 4: Total time: 12 + 4 + 20 = 36 minutes
  Arrival: 8:00 AM + 36 min = 8:36 AM
Without the #Steps# section, the model may skip intermediate calculations and produce an incorrect answer.

Use delimiters to separate content

When a prompt contains multiple blocks of content -- instructions, input data, and examples -- use delimiters to mark clear boundaries. This helps the model distinguish your instructions from the content it should process. Use character sequences that rarely appear in natural language: ###, ===, or >>>. Example: Text summarization
Summarize each section of the following movie review separately.
Produce one summary sentence per section.

###
Zhang Zhiqiang was once spirited and energetic, but life's pressures
pushed him off course. An impulsive decision in middle age transformed
him from his family's pride into a social outcast.
###
This was just the beginning. A series of unexpected events forced him
to confront himself. He chose to start over as a delivery driver,
navigating city streets to rebuild his life.
###
Along the way, he found like-minded companions. Through their shared
struggles, he rediscovered his courage and purpose, forging a new
direction for his life.
###
Without delimiters, the model treats the entire review as a single block and produces one generic summary. With delimiters, it identifies three distinct sections and generates three related summaries that follow the narrative arc.

Guide the model to reason step by step

For tasks involving logic, math, or multi-step analysis, have the model show its reasoning before stating a conclusion. Two effective techniques:

Chain of Thought (CoT)

CoT is a relatively simple method that can significantly improve the reasoning of LLMs in complex scenarios. Ask the model to explain its thinking before producing a final answer. Example: JSON validation
#Context#
JSON input:
{"web-app": {
  "servlet": [
    {
      "servlet-name": "cofaxEmail",
      "servlet-class": "org.cofax.cds.EmailServlet",
      "init-param": {
        "mailHost": "mail1",
        "mailHostOverride": "mail2"}},
    {
      "servlet-name": "cofaxTools",
      "servlet-class": "org.cofax.cms.CofaxToolsServlet",
      "init-param": {
        "templatePath": "toolstemplates/",
        "log": 1,
        "logLocation": "/usr/local/tomcat/logs/CofaxTools.log",
        "logMaxSize": ""}}],
  "servlet-mapping": {
    "cofaxEmail": "/cofaxutil/aemail/*",
    "cofaxTools": "/tools/*"},
  "taglib": {
    "taglib-uri": "cofax.tld",
    "taglib-location": "/WEB-INF/tlds/cofax.tld"}}}

#Objective#
Verify whether this JSON meets all three requirements:
1. Every servlet has an init-param block.
2. Every key in servlet-mapping matches a servlet-name.
3. The cofaxTools servlet has exactly three parameters starting with
   "log", and the "log" parameter value is less than 10.

#Response#
First, explain your reasoning for each requirement.
Then state whether all requirements are met.
Adding "explain your reasoning" produces a structured analysis where the model evaluates each requirement individually -- catching edge cases (like the empty string value of logMaxSize) that it would miss with a yes/no-only output.

Prompt chaining

Break a complex problem into a sequence of simpler questions across multiple turns. Each answer feeds into the next question, guiding the model along a controlled reasoning path. Prompt chaining takes more effort to set up than CoT but performs better and has higher accuracy. It is particularly suitable for tasks that are logically complex but can be broken down according to fixed patterns. Example: Multi-step math (same Timmy problem, three turns) Turn 1:
#Context#
Timmy leaves at 8:00 AM walking at 50 m/min. After 12 minutes, his
father chases on a bicycle at 200 m/min. The bicycle distance is
5 times the walking distance.

#Question#
When does the father catch Timmy, and how far has Timmy walked?
Model: "The father catches Timmy at 8:16 AM, after Timmy has walked 800 meters." Turn 2:
How far does Timmy travel by bicycle to reach his grandparents' house?
Model: "Bicycle distance = 800 m * 5 = 4,000 meters." Turn 3:
What time does Timmy arrive?
Model: "Bicycle time = 4,000 m / 200 m/min = 20 minutes. Total time = 16 + 20 = 36 minutes. Arrival: 8:36 AM." Each turn builds on verified intermediate results, reducing the chance of compounding errors.
Other reasoning techniques include Tree of Thoughts (ToT) and Boosting of Thoughts. Choose the technique that matches your task complexity and accuracy requirements.

Test and iterate

Prompt engineering is iterative. Rarely does the first version of a prompt produce the best results.
Prompt iteration cycle diagram
Follow this cycle:
  1. Define your goal. Decide what good output looks like before writing the prompt.
  2. Write an initial prompt. Apply the techniques from this guide: be specific, use a framework, and provide examples.
  3. Test with diverse inputs. Run the prompt against multiple real-world scenarios, including edge cases.
  4. Analyze failures. Identify where output falls short: wrong format, missing information, incorrect reasoning, or inconsistent tone.
  5. Refine the prompt. Adjust one element at a time to measure the effect of each change.
  6. Repeat. Continue until output consistently meets your quality bar.
Beyond prompt design, user feedback is essential. After deploying a prompt in production, monitor real interactions and refine based on patterns in user corrections and edge cases you did not anticipate.

Example: Optimize a multilingual HR assistant

Background: A Qwen3.5-Flash-based HR assistant for a multinational company was not consistently responding in the user's language. The system prompt needed restructuring.

Before optimization

# Role
You are an efficient HR AI assistant, specifically responsible for
answering company internal questions about policies, attendance
systems, annual leave arrangements, and other related issues.

## Skills
### Skill 1: Policy interpretation
- Accurately interpret company policy documents and provide clear,
  concise policy explanations to colleagues.

### Skill 2: Attendance Q&A
- Answer all questions related to employee attendance, including
  clock-in rules, handling of late arrivals and early departures,
  leave procedures, etc.

### Skill 3: Annual leave management consultation
- Explain annual leave application conditions, accumulation rules,
  validity period, and approval process.

## Limitations
- Respond in the same language as the user's question.
- Limited to HR-related questions.
- Do not involve queries of personal privacy data.
Issues:
  • Loose structure with a redundant ## Limitations section
  • The ${documents} knowledge base block was embedded inline, making it hard for the model to distinguish instructions from reference content
  • Language-matching instructions were buried in limitations

After optimization

#Context#
You are an HR AI assistant for a multinational company. You answer
questions about policy interpretation, attendance rules, and annual
leave management.

Below are the company policy documents:
======
${documents}
======

#Objective#
1. Only answer questions about policy interpretation, attendance,
   and annual leave.
2. When a question is in scope but the knowledge base does not cover
   it, direct the user to contact the HR department.
3. For each category, follow these guidelines:
   - Policy interpretation: Locate the relevant clause and provide
     a clear, concise explanation.
   - Attendance: Cover clock-in rules, late arrival handling, and
     leave procedures.
   - Annual leave: Explain eligibility, accrual rules, approval
     process, and help calculate remaining balance.
4. Do not access or disclose personal employee data.

#Multilingual requirements#
- If the question is not in Chinese, translate it to Chinese to
  search the knowledge base, then convert the retrieved content
  back to the question's language for output.

#Response#
- Use only standard ASCII characters in all output.
- Match the output language to the input language.
What changed:
  • Framework applied. Restructured using #Context#, #Objective#, #Multilingual requirements#, and #Response# sections.
  • Delimiters added. Wrapped ${documents} in ====== delimiters to separate reference data from instructions.
  • Constraints distributed. Moved constraints into their relevant sections (language rules into #Multilingual requirements#, scope limits into #Objective#).
These changes resolved the language-consistency issue because the model could clearly identify the multilingual instruction as a distinct, high-priority directive rather than a buried afterthought.