Runoob Tutorial ArchiveEnglish

Prompt

Prompt

Master the fundamentals of conversing with AI—writing good prompts and using AI tools effectively.

Why prompts are important

The same question, different ways of asking, yield vastly different quality answers.

You might have experienced this:

You ask AI: "Help me write a report." AI gives you a vague and empty article.

But if you change the prompt to ask: "I am a product manager, help me write a product roadmap report for Q2 2026, the target audience is the technical team, it needs 5 main features, each feature must include a development cycle and risk assessment, and the word count should be under 800 words." AI provides a document that is clearly structured, specific in content, and immediately usable.

This is the difference in prompts.

The Prompt is the language you use to communicate with the AI.

The AI can only respond based on the information you provide; the more specific and clear the information, the more the output will meet expectations.

The golden rule of prompts:Vague input leads to vague output; specific input leads to specific output..


What is a Prompt?

A Prompt is the text content you input to the AI.

A prompt can be a question, an instruction, a description, or a combination of these.

Good Prompt vs Bad Prompt

We use a comparison to illustrate the difference between the two:

Dimension ❌ Not recommended way ✅ Recommended way
Clarity "Help me write something" "Help me write an email to the client informing them that our product will increase in price by 10% next month"
Role setting "Translate this passage" "You are a professional English translator specializing in technical documentation translation. Please translate the following content into Chinese while maintaining the accuracy of technical terms"
Formatting requirements "List items" "List 5 points using an unordered list, with each point not exceeding 20 characters"
Context "Help me look at this code" "This is a Python web scraping code that throws a 'connection timeout' error when running. Please analyze the possible causes and provide 3 solutions."
Style and tone "Write a notice" "Write a holiday notice for all company employees. The tone should be formal, the content concise, and it must include three parts: holiday dates, precautions, and on-duty arrangements."

Do you see the pattern?

A good prompt tells the AI: who you are, what to do, who it's for, what format to use, and what constraints to follow.


Basic prompt structure

A complete prompt usually includes the following four elements.

You don't have to write all of them every time, but the more comprehensive they are, the more controllable the results will be.

Task description (what to do)

Clearly tell the AI what task you want it to complete.

This is the core part of the prompt and must be clearly written.

Summarize the main points of this article.

Convert this Python code to JavaScript.

Help me come up with 10 suitable names for a milk tea shop.

Background information (context)

Provide the AI with relevant background information to help it understand the task scenario.

Without context, the AI can only guess randomly. When context is provided, its answers will be on point.

I am a third-year computer science student preparing for an interview...

This is our company's product introduction, and the target customers are small and medium-sized business owners...

I need to write a popular science article for elementary school students; I cannot use complex terminology...

Output format requirements (how to present)

Specify the format in which the AI should output: list, table, paragraph, code, JSON, etc.

Clear format requirements will save you time on secondary organization.

Present in a table format, including three columns: Step Name, Operation Description, and Notes.

Output in JSON format, containing three fields: 'id', 'name', and 'description'.

Answer in three paragraphs, with each paragraph not exceeding 100 characters.

Example (provide a reference)

Give the AI one or two examples so it understands what kind of output you want.

This is called Few-shot Learning, which means providing a few examples for learning.

For example:

Input: happy, Output: ecstatic, overjoyed, delighted

Please process now: sad


Three basic prompt types

Depending on your goal, prompts can be divided into three basic types.

Question type: ask directly

Used to obtain information, explain concepts, or seek advice.

This is the simplest prompt type, suitable for information query scenarios.

What is the difference between list and tuple in Python?

How to improve team communication efficiency?

What are the most worthwhile frontend frameworks to learn in 2026?

When asking questions, note: the more specific, the better.

Don't just ask: How to learn programming, ask: I am a complete beginner and want to do web development, should I learn HTML/CSS or JavaScript first? Please provide a 3-month study plan.

Command-type: Telling the AI what to do

Used to complete specific tasks: writing, translating, modifying code, organizing data, etc.

Command-type prompts need to be clear, specific, and actionable.

Translate this text into English while maintaining the original humor.

Split this long paragraph into 5 small points, and add a small title to each point.

Help me optimize this code, add comments, and find potential bugs.

Conversational: Multi-turn interaction

Not a one-time question, but a continuous conversation that gradually deepens.

This method is suitable for complex tasks, allowing direction adjustment while chatting.

You: "I want to build a personal blog website, what technical solutions do you recommend?"

AI: "Based on your needs, you can consider the following solutions: ..."

You: "I choose Hugo, so how do I start specifically?"

AI: "Okay, here are the steps to build a blog using Hugo: ..."

You: "Wait, I don't want to use GitHub Pages, are there any other free hosting options?"

The key to conversational prompts is: remember that the AI has context memory. You don't need to repeat the previous content every time; you can just continue the conversation.


Role-playing prompts

Assigning a role to the AI will make its answers more professional and context-appropriate.

This is one of the simplest yet most effective techniques.

Why role-playing is useful

During its training, the AI has seen a large amount of text from different roles. When you tell it "you are a lawyer," it automatically adjusts its tone, vocabulary, and way of thinking to be more like a real lawyer.

The same question will yield completely different answers depending on the role.

For example, if you ask: "How can I let more people know about my product?"

Set the role Focus of the answer
Marketing expert Brand positioning, channel selection, campaign planning
Sales director Conversion funnel, customer follow-up, closing techniques
Product Manager Product selling points, user experience, differentiation
Technical Lead Technical implementation, performance optimization, data analysis

Common role templates

Here are some common role settings that you can use directly or modify as needed:

You are an experienced Python development engineer skilled in code review and performance optimization, please help me review this code...

You are a professional copywriter with 10 years of experience in the advertising industry, please help me rewrite this product description...

You are my Japanese tutor, with standard pronunciation, skilled at correcting beginner mistakes, please help me check the grammar of this conversation...

You are an entrepreneur mentor who has successfully founded three tech companies, please help me analyze this business plan...

The more specific the role setting, the better the effect.

Don't just say "you are an expert," say "you are an expert with 5 years of e-commerce data analysis experience, especially skilled in user behavior analysis."


Techniques for more precise output

Mastering these techniques will greatly increase your prompt engineering skills.

Specify the output format

Clearly telling the AI what format to output can save you a lot of time in organizing.

Common formats include:

Format type Example instruction
List "List 5 points using an unordered list..."
Table "Present in a table, column names: Function, Advantages, Disadvantages..."
Code Output the complete Python code, including comments...
JSON Output in JSON format, fields: id, name, price...
Markdown Use Markdown format, including 3 subheadings...

Control length

Tell the AI how long you want the output to be to prevent it from being too long or too short.

Summarize in one sentence...

Write an introduction of about 300 words...

Provide a detailed explanation of at least 500 words...

Specify the tone and style

Tell the AI what tone to use, adapting to different communication scenarios.

Formal tone, suitable for leaders to view...

Express in a relaxed and humorous way...

Use plain and easy-to-understand language, suitable for elementary school students to understand...

Maintain a professional, objective, and neutral tone...

Chain of Thought

For complex problems, ask the AI to articulate its thought process instead of just providing the answer.

This can significantly improve the accuracy of the answer and makes it easier for you to check its reasoning process.

Please analyze this problem step by step, first stating your approach, and then providing the answer.

When encountering uncertain points, please state your assumptions and reasoning process.


Common Errors and Corrections

Beginners are prone to making these mistakes; let's look at how to correct them.

Error One: Prompt is too vague

This is the most common problem.

❌ Vague prompts ✅ Improved prompts
"Help me write some copy" "Help me write a WeChat official account copy for a new milk tea shop product launch, targeting young people aged 18-25, with a lively and interesting style, highlighting the 'second cup half price' promotion, and with a word count of 300-500 words"
"Help me look at this code" "This is a user registration API code written in Python; please check for SQL injection risks, password encryption security, and completeness of error handling, listing the issues and suggested fixes separately"
"Help me make a plan" "Help me create a 3-month fitness plan with the goal of losing 5 kg, exercising 3 times a week for 1 hour each time, with running and strength training as the main modes of exercise. Please provide a detailed weekly schedule."

Error two: Too many requests, cannot be covered in one go.

Do not try to do everything in a single prompt.

Complex tasks should be divided into multiple turns of conversation, step by step.

❌ Don't do this: "Help me write an e-commerce website that has user registration, product display, shopping cart, order management, and payment functionality, developed with React and Node.js, and using MySQL for the database. Give me the complete code."

✅ Do this:

You: "I want to make a simple e-commerce website, and I want to use React + Node.js + MySQL as the tech stack. What should I do first?"

AI: "I suggest designing the database table structure first. We can start with the user table and the product table..."

You: "Okay, help me design the structure for the user table and the product table. What fields should be included?"

... (digging deeper step by step)

Error three: No feedback, and sticking to the mistake.

The AI's first output may not be perfect.

It's okay, tell it what's wrong and let it revise.

You: "This article is too long and too technical. My readers are beginners and can't understand it."

AI: "Sorry, I will rewrite it to be more concise and easy to understand..."

You: "Much better, but the second part is still a bit complicated. Can you explain this concept using an analogy?"

AI: "Okay, let's use 'sending a package' to analogize this network communication process..."

Remember: Prompting is an iterative process. Rarely is it perfect in one go.


Practical Exercises: 10 High-Frequency Use Case Templates

Here are 10 of the most commonly used prompt templates that you can use directly.

Scenario Prompt Template
Email Writing You are a professional business writing assistant. Please help me write an email to {recipient role} with the subject {email subject}, the main content being {specific content}, and the tone being {formal/friendly/tactful/direct}, keeping the word count within {number} words.
Article Summary Please read the following article and generate a summary of {word_count} words, including the following points: 1) {core_point_one}; 2) {core_point_two}; 3) {core_point_three}. Please summarize in clear and concise language.
Code Explanation You are a patient programming teacher. Please help me explain the function of this {programming_language} code, explain the function of key statements line by line, and point out the strengths, weaknesses, and potential areas for improvement of this code.
Translation You are a professional {source_language} to {target_language} translator, specializing in {domain} translation. Please translate the following content into {target_language} with the following requirements: 1) Maintain the accuracy of professional terminology; 2) Conform to the expression habits of {target_language}; 3) Style {formal/colloquial}.
Meeting Minutes Please organize meeting minutes based on the following meeting records, including: 1) Meeting time, location, and attendees; 2) Main discussion topics; 3) Resolutions reached; 4) To-do items and responsible persons. Please present in clear and concise language.
Resume Optimization You are a senior HR consultant. Please help me optimize this resume description to make it more professional and persuasive. Please rewrite it using the format "Verb + Achievement," quantify work results, use industry keywords, and highlight personal contributions.
Learning Plan I want to learn {knowledge/skill}, my current foundation is {basic description}, and my goal is {specific goal}. I have {time arrangement} available. Please help me create a {duration} learning plan, listing the learning content, recommended resources, and verification methods for each stage.
Brainstorming I want to brainstorm {topic/problem}. Please help me come up with {number} creative ideas, with the following requirements: 1) Not limited to conventional thinking; 2) Consider feasibility; 3) Describe the core idea and possible implementation method for each idea in one sentence.
Troubleshooting I encountered an issue: {problem description}. I have already tried {methods tried}, but none of them solved it. Please help me analyze the possible causes, list them from most to least likely, and provide corresponding troubleshooting steps and solutions.
Content Rewriting Please help me rewrite the following content, with the target audience being {reader group}, the style requirement being {style description}, and the word count being {word count requirement}. Please retain the core information, but express it in a more {popular/professional/concise/detailed} manner.

These templates can be flexibly adjusted according to specific situations.

The key is: break down vague requirements into specific elements and fill them into the template one by one.


Example of calling AI with code

Besides entering prompts in the chat interface, you can also call the AI API through code.

We will use Python to demonstrate:

Example

============================================

Use Python to call the AI API and send prompts

This example shows how to structure your prompts

============================================

import

json

from

typing

import

Dict

,

Optional

class

PromptBuilder:

   

"""Prompt builder, helps you structure prompts"""

   

def

init

(

self

)

:

       

self

.

role

=

None

         

Role setting

       

self

.

task

=

None

         

Task description

       

self

.

context

=

None

     

Background information

       

self

.

format

=

None

       

Output format

       

self

.

examples

=

[

]

       

Examples

       

self

.

constraints

=

[

]

   

Constraints

   

def

set_role

(

self

,

role:

str

)

"PromptBuilder"

:

       

"""Set the AI's role"""

       

self

.

role

=

role

       

return

self

   

def

set_task

(

self

,

task:

str

)

"PromptBuilder"

:

       

"""Set the task"""

       

self

.

task

=

task

       

return

self

   

def

set_context

(

self

,

context:

str

)

"PromptBuilder"

:

       

"""Set background information"""

       

self

.

context

=

context

       

return

self

   

def

set_format

(

self

,

format_spec:

str

)

"PromptBuilder"

:

       

"""Set the output format"""

       

self

.

format

=

format_spec

       

return

self

   

def

add_example

(

self

,

input_example:

str

,

output_example:

str

)

"PromptBuilder"

:

       

"""Add examples"""

       

self

.

examples

.

append

(

{

"input"

: input_example

,

"output"

: output_example

}

)

       

return

self

   

def

add_constraint

(

self

,

constraint:

str

)

"PromptBuilder"

:

       

"""Add constraints"""

       

self

.

constraints

.

append

(

constraint

)

       

return

self

   

def

build

(

self

)

str

:

       

"""Construct the final prompt"""

parts

=

[

]

       

if

self

.

role

:

parts.

append

(

f

"Role: {self.role}"

)

       

if

self

.

context

:

parts.

append

(

f

"Context: {self.context}"

)

       

if

self

.

task

:

parts.

append

(

f

"Task: {self.task}"

)

       

if

self

.

examples

:

parts.

append

(

"Example:"

)

           

for

i

,

example

in

enumerate

(

self

.

examples

,

1

)

:

parts.

append

(

f

" Input {i}: {example['input']}"

)

parts.

append

(

f

" Output {i}: {example['output']}"

)

       

if

self

.

format

:

parts.

append

(

f

"Output format: {self.format}"

)

       

if

self

.

constraints

:

parts.

append

(

"Constraints:"

)

           

for

constraint

in

self

.

constraints

:

parts.

append

(

f

" - {constraint}"

)

       

return

"\n"

.

join

(

parts

)

def

simulate_ai_call

(

prompt:

str

,

api_key: Optional

[

str

]

=

None

)

Dict:

   

"""
Simulate AI API call (replace with actual API call in a real project)
This only demonstrates how to use structured prompts
"""

   

print

(

"="

60

)

   

print

(

"Prompt sent to AI:"

)

   

print

(

"-"

60

)

   

print

(

prompt

)

   

print

(

"="

60

)

   

This is for demonstration only; a real project will call actual APIs

   

For example: OpenAI API, Anthropic API, etc.

   

return

{

       

"status"

:

"success"

,

       

"prompt_sent"

: prompt

,

       

"message"

:

"This is a simulated AI response (will be replaced by the actual API response when used)"

,

       

"tips"

:

In a real runoob project, please configure your API Key and call the actual API

   

}

============================================

Usage Example 1: Write Email

============================================

print

(

"Example 1: Write an email"

)

prompt1

=

(

PromptBuilder

(

)

.

set_role

(

"You are a professional business writing assistant specializing in English email writing"

)

.

set_context

(

I am a marketing manager at runoob company and need to write a follow-up email to a client.

)

.

set_task

(

"Write an email asking for the client's feedback on our product proposal and scheduling a meeting for next week."

)

.

set_format

(

"Email format, including: subject, salutation, body, signature"

)

           .

add_constraint

(

"Tone is friendly but professional"

)

.

add_constraint

(

"No more than 200 words"

)

.

build

(

)

)

result1

=

simulate_ai_call

(

prompt1

)

print

(

f

"API Status: {result1['status']}"

)

============================================

Usage Example 2: Code Optimization

============================================

print

(

"\n【Example 2: Code Optimization】"

)

prompt2

=

(

PromptBuilder

(

)

.

set_role

(

"You are an experienced senior Python engineer skilled in code review"

)

.

set_task

(

"Optimize the following code to make it more efficient and readable"

)

.

set_context

(

"This is code for processing student grade data, and the running speed is a bit slow."

)

.

set_format

(

"Output the optimized code and explain the reason for the changes in comments."

)

.

add_constraint

(

"Keep original functionality unchanged"

)

           .

add_constraint

(

"Compatible with Python 3.8+"

)

.

build

(

)

)

result2

=

simulate_ai_call

(

prompt2

)

print

(

f

"API Status: {result2['status']}"

)

Running this code will show you how structured prompts are built.

In a real project, you need to replace it with actual API calls (such as OpenAI, Anthropic, or other vendors' APIs).