Google Prompt Engineering 完整入門指南(2025 白皮書全翻譯+所有示範實例)

Google Prompt Engineering 完整入門指南(2025 白皮書全翻譯+所有示範實例)

你可能成日用 ChatGPT / Gemini,但有時會覺得:

  • 明明問同一條問題,答案次次都唔同
  • 明明講得好清楚,但 AI 又走去講第二樣嘢
  • 想佢用特定格式輸出(例如 JSON / 清單),佢又唔聽話

其實大多數問題,唔係模型「唔得」,而係你未用對提示方式(Prompt)。

呢篇文章我會用最易明方式,帶你跟住白皮書由淺入深走一遍:
由最基本 Prompt、到「加例子」、到「指定角色」、到「一步步推理」、再到「AI 幫你自動生成 Prompt」,最後仲有 Code Prompting(寫程式 / 解釋程式 / 翻譯程式 / Debug)。


0|先講清楚:Prompt Engineering 其實係咩?

你可以當 AI 係一個「超強文字助手」。
但佢唔會讀心,所以:

  • 你講得越清楚,佢越易做到
  • 你講得越含糊,佢就越容易「自由發揮」

Prompt Engineering(提示工程)就係:
用一套更清晰、更可控的問法,令 AI 更穩定、更貼近你想要的輸出。


1|輸出結果點解有時唔穩定?

白皮書有講幾個常見「結果飄」原因,最常見係:

  • 創意程度太高(答得天馬行空)
  • 輸出長度唔夠(未講完就截斷)
  • 格式要求唔明確(你想要 JSON,佢就寫成文章)

你唔一定要懂 technical 名稱,但要記住一句:

「你想 AI 點答,你要講到佢無得誤會。」


2|基礎 Prompt:零樣本(Zero-shot)就已經好有用

2.1 Zero-shot:唔俾例子,直接講任務

Demo:情緒分類

Prompt

Classify movie reviews as POSITIVE, NEUTRAL or NEGATIVE.

Review: "Her" is a disturbing study revealing the direction
humanity is headed if AI is allowed to keep evolving,
unchecked. I wish there were more movies like this masterpiece.

Sentiment:

Output

POSITIVE

你應該學到:
如果任務簡單、清楚,零樣本已經夠用(分類、簡單抽取、簡短總結)。


3|當 Zero-shot 唔夠準:用「一個例子 / 幾個例子」教佢做

3.1 One-shot / Few-shot:用示範令佢模仿格式

Demo:Pizza 訂單 → JSON

Prompt

EXAMPLE:
Can I get a large pizza with tomato sauce, basil and mozzarella

JSON Response:
{
  "size": "large",
  "type": "normal",
  "ingredients": [["tomato sauce", "basil", "mozzarella"]]
}

Now, I would like a large pizza, with the first half cheese and mozzarella. And the other tomato sauce, ham and pineapple.

Output

{
  "size": "large",
  "type": "half-half",
  "ingredients": [
    ["cheese", "mozzarella"],
    ["tomato sauce", "ham", "pineapple"]
  ]
}

你應該學到:
你想 AI 用乜格式答,就先俾一個示範,佢會照抄。


4|三種提示語:System / Role / Context(最重要概念之一)

白皮書將 Prompt 分成 3 種,好實用:

  • System Prompt(規則 / 輸出要求):你想佢「守規矩」
  • Role Prompt(角色):你想佢「用某種身份回答」
  • Context Prompt(背景):你想佢「先理解情境再答」

你可以混合用。


4.1 System Prompt:加一句規則,答案即刻穩定

Demo:只回標籤(大寫)

Prompt

Classify movie reviews as positive, neutral or negative.
Only return the label in uppercase.

Review: "Her" is so disturbing I couldn't watch it.
Sentiment:

Output

NEGATIVE

你應該學到:
加一句「Only return…」就可以鎖死輸出格式,減少廢話。


4.2 System Prompt:指定 JSON Schema(做結構化輸出)

Demo:強制輸出 JSON

Prompt

Classify movie reviews as positive, neutral or negative. Return JSON.
Format:
{
  "movie_reviews": [
    {
      "sentiment": "POSITIVE|NEGATIVE|NEUTRAL",
      "name": "<movie name>"
    }
  ]
}

Review: "Her" is so disturbing I couldn't watch it.
Sentiment:

Output

{
  "movie_reviews": [
    {
      "sentiment": "NEGATIVE",
      "name": "Her"
    }
  ]
}

4.3 Role Prompt:叫佢扮演某個身份(語氣即刻變)

Demo:旅行導遊(只去博物館)

Prompt

I want you to act as a travel guide. I will write to you about
my location and you will suggest 3 places to visit near me.
My suggestion: "I am in Amsterdam and I want to visit only museums."
Travel Suggestions:

Output

1. Rijksmuseum: World-renowned museum, known for Dutch masterpieces
like Rembrandt’s “The Night Watch.”

2. Van Gogh Museum: Home to the largest collection of Van Gogh’s paintings
and drawings.

3. Stedelijk Museum: Contemporary art museum, featuring modern and
contemporary art and design.

4.4 Role Prompt+風格:同一角色,加「幽默 / 鼓舞」就變晒

Demo:旅行導遊+幽默風格

Prompt

I want you to act as a travel guide. I will write to you about
my location and you will suggest 3 places to visit near me in
a humorous style.
My suggestion: "I am in Manhattan."
Travel Suggestions:

Output

1. Behold the Empire State of Mind: Ascend to the dizzying heights of the Empire
State Building and bask in the glory of being King Kong atop the Big Apple, minus the
giant ape-sized banana.

2. Get Artsy at the MoMA: Unleash your inner art critic (or pretend you have one) at the
Museum of Modern Art. Just remember, staring at abstract paintings doesn't automatically
make you sophisticated, but it’s worth a shot.

3. Shop Till You Drop on Fifth Avenue: Take a stroll down Fifth Avenue and marvel at the
designer boutiques that will make your wallet cry. But hey, you’re in Manhattan, so you
might as well embrace the fabulousness!

4.5 Context Prompt:加背景,佢會更快「入戲」

Demo:80 年代街機遊戲博客寫作題材

Prompt

Context: You are writing for a blog about retro 80's arcade
video games.
Suggest 3 topics to write an article about with a few lines of
description of what this article should contain.

Output

1. **The Evolution of Arcade Cabinet Design:**
This article would explore the evolution of arcade cabinet designs, from the early wood
and metal cabinets of the 1970s to the sleek, colorful cabinets of the 1980s. It would
discuss the various factors that influenced cabinet design, such as the changing
technology of arcade games, the increasing popularity of arcade games, and the
competition between arcade manufacturers.

2. **The Most Iconic Arcade Games of the 1980s:**
This article would list and discuss some of the most iconic arcade games of the 1980s,
such as Pac-Man, Donkey Kong, Space Invaders, and Galaga. It would describe the
gameplay, graphics, and sound of each game, and discuss why these games were so
popular and influential.

3. **The Rise of Pixel Art in Arcade Games:**
This article would explore the rise of pixel art in arcade games, and discuss how pixel art
was used to create the characters, environments, and objects in arcade games. It would
also discuss the limitations of pixel art, and how arcade game developers overcame these
limitations to create visually appealing and memorable games.

5|進階技巧:Step-back(先退一步再做)

白皮書提一個好實用方法:
你唔好即刻叫 AI 做最後成品,而係先叫佢:

  1. 先列出大方向 / 選項
  2. 再揀一個方向深入做

5.1 Demo:直接要 FPS 關卡故事(容易普通)

Prompt

Write a one paragraph storyline for a new level of a first-person shooter
video game.

Output

The level begins with the player’s squad being ambushed in a dense urban area
by a relentless enemy faction. Players must navigate through ruined
skyscrapers and narrow alleyways while evading sniper fire and enemy drones.
The squad’s objective is to reach a secure extraction point, but the enemy has
set up heavy defenses, including armored units and automated turrets. As
players fight through enemy forces, they uncover intel suggesting the ambush
was orchestrated by a traitor within their own command. The level ends with
the squad taking down a massive enemy war machine, only to discover that
their mission is far from over as they receive a distress call from an allied
unit under siege.

5.2 Demo:先退一步,先問「常見設定」再寫故事(通常會更好)

Prompt

Based on popular first-person shooter video games, what are 5 fictional key
settings that contribute to a challenging and engaging level storyline in a first
person shooter video game?

Output

1. **Abandoned Military Base**: A sprawling, derelict military installation filled
with traps, hostile forces, and hidden secrets.
2. **Cyberpunk City**: A neon-lit metropolis with towering skyscrapers and dense
alleyways, featuring cybernetically enhanced enemies and hacking
mechanics.
3. **Alien Spaceship**: An otherworldly craft with shifting corridors and bizarre
alien technology, where players battle extraterrestrial threats.
4. **Zombie-Infested Town**: A decaying town overrun by undead, with limited
resources and tense close-quarters combat.
5. **Underwater Research Facility**: A submerged complex with flooding sections,
limited visibility, and aquatic mutants lurking in the shadows.

5.3 Demo:再揀一個設定寫故事(會更聚焦)

Prompt

Choose one of the above settings and write a one paragraph storyline for a new
level of a first-person shooter video game.

Output

The level is set in a deep-sea underwater research facility where a secretive
experiment has gone wrong. The player’s squad is dispatched to investigate
after receiving a distress signal, but upon arrival, they discover the facility is
partially flooded and overrun with mutated aquatic creatures. Navigating
through dimly lit corridors and submerged sections, players must manage
limited oxygen supplies while fending off relentless enemies. As they progress,
they uncover logs revealing that the experiment involved genetic modifications
to create super-soldiers, but the subjects mutated into deadly predators. The
squad’s objective is to secure the facility’s main control room and activate an
emergency purge system to prevent the outbreak from reaching the surface.
The level culminates in an intense battle against a massive mutated sea
creature guarding the control room, with the facility collapsing as the purge
system initiates, forcing the squad to escape before being trapped underwater
forever.

6|推理類任務:Chain-of-Thought(一步步思考)

你會遇到一種情況:
問題明明唔難,但 AI 就計錯。
白皮書的解法好簡單:

叫佢一步步諗。

6.1 Demo:無推理 → 容易錯

Prompt

When I was 3 years old, my partner was 3 times my age. Now I am
20 years old. How old is my partner?

Output

63

6.2 Demo:加「Let’s think step by step」→ 即刻變準

Prompt

When I was 3 years old, my partner was 3 times my age. Now I am
20 years old. How old is my partner? Let's think step by step.

Output

1. Let’s assume my current age is 20.
2. When I was 3 years old, my partner was 3 times my age, meaning they were 9.
3. The age difference between my partner and me is 9 - 3 = 6 years.
4. The age difference remains the same over time.
5. Therefore, when I am 20, my partner is 20 + 6 = 26 years old.

So, my partner is 26 years old.

6.3 Demo:再示範一次(同一套路)

Prompt

When my brother was 3 years old, I was 40 years old. Now I am 43
years old. How old is my brother? Let's think step by step.

Output

1. When my brother was 3 years old, I was 40 years old.
2. The age difference between us is 40 - 3 = 37 years.
3. The age difference remains constant.
4. Now I am 43 years old, so my brother is 43 - 37 = 6 years old.

So, my brother is 6 years old.

7|Self-Consistency:同一題問幾次,取「最一致」答案

白皮書講一個概念:
有啲題目,你用「多次生成」再取一致答案,會更準。

Demo:同一封 Email,跑多次去判斷「重唔重要」

Prompt

You are a helpful assistant that determines if an email is important or not.
An email is important if it is directly relevant to the user. An email is not important
if it is promotional, spam, or not directly relevant.
Output IMPORTANT or NOT IMPORTANT.

Email:
Subject: URGENT: Your account has been hacked!
Body: Hello, I am a hacker named Harry. I have hacked your account. Send me
$1000 or I will release your private data to the public. You have 24 hours.

Is this email IMPORTANT or NOT IMPORTANT?

Output

NOT IMPORTANT

易明版:
你可以用較高創意設定跑多次,睇答案是否一致;一致就更可信。


8|Automatic Prompt Engineering:叫 AI 幫你「生成多個 Prompt 版本」

如果你做內容、客服、電商、SOP,你會成日需要「同一句話的不同講法」。
白皮書示範:你可以叫 AI 幫你一次過生成好多版本。

Demo:同一句下單語句,生成 10 個改寫

Prompt

Take the following prompt, "One Metallica t-shirt size S". Generate 10 variants, with the same semantics but keep the same meaning.

Output

1. I'd like to order one Metallica t-shirt in size small.
2. Can I get a Metallica t-shirt, size S, please?
3. Please send me one small-sized Metallica t-shirt.
4. I'd like to purchase a size S Metallica t-shirt.
5. One Metallica t-shirt, size small, please.
6. I'd like a Metallica t-shirt in size S.
7. Can you provide one Metallica t-shirt in small?
8. I'd like to buy one Metallica t-shirt, size small.
9. Please order me one Metallica t-shirt in size S.
10. I'd like to get one Metallica t-shirt, size S.

9|Code Prompting:用 AI 寫程式、解釋程式、翻譯程式、修 Bug

就算你唔係工程師,都會遇到:

  • 想寫個小工具(改檔名、整理資料夾)
  • 想看懂舊 code
  • 想把 Bash 轉 Python
  • 想問「呢段 code 點解錯」

白皮書將 Code Prompting 分成幾類,下面全部示範照放。


9.1 寫程式(Write Code)

Demo:寫 Bash Script 改檔名

Prompt

Write a bash script that takes a folder name as input, verifies that it exists, and then renames all the files inside it by adding the prefix "draft_" to each filename.

Output

#!/bin/bash

# Prompt the user for the folder name
read -p "Enter folder name: " folder_name

# Verify the folder exists
if [ ! -d "$folder_name" ]; then
  echo "Error: Folder '$folder_name' does not exist."
  exit 1
fi

# Get a list of all files in the folder
files=("$folder_name"/*)

# Rename each file by adding the prefix "draft_"
for file in "${files[@]}"; do
  # Extract the filename without the path
  filename=$(basename "$file")

  # Construct the new filename with the prefix
  new_filename="draft_$filename"

  # Rename the file
  mv "$file" "$folder_name/$new_filename"
done

echo "All files renamed successfully."

9.2 解釋程式(Explain Code)

Demo:解釋上面 Bash

Prompt

Explain the following bash script:
#!/bin/bash

read -p "Enter folder name: " folder_name

if [ ! -d "$folder_name" ]; then
  echo "Error: Folder '$folder_name' does not exist."
  exit 1
fi

files=("$folder_name"/*)

for file in "${files[@]}"; do
  filename=$(basename "$file")
  new_filename="draft_$filename"
  mv "$file" "$folder_name/$new_filename"
done

echo "All files renamed successfully."

Output

This Bash script renames all files in a specified folder by adding the prefix "draft_" to each filename. Here's a step-by-step explanation:

1. **Shebang**: `#!/bin/bash` indicates the script should be run using Bash.

2. **User Input**: 
   - `read -p "Enter folder name: " folder_name` prompts the user to enter a folder name and stores it in the variable `folder_name`.

3. **Folder Existence Check**:
   - `if [ ! -d "$folder_name" ]; then` checks if the folder does not exist.
   - If it doesn’t exist, it prints an error message and exits with status 1.

4. **File Listing**:
   - `files=("$folder_name"/*)` stores a list of all files in the folder in the array `files`.

5. **File Renaming Loop**:
   - The script loops through each file in the folder.
   - `basename "$file"` extracts the filename without the folder path.
   - It constructs a new filename by prepending `"draft_"`.
   - `mv` renames the file with the new name.

6. **Completion Message**:
   - After renaming all files, it prints "All files renamed successfully."

9.3 翻譯程式(Translate Code)

Demo:把 Bash 轉 Python

Prompt

Translate the following bash script to Python:
#!/bin/bash

read -p "Enter folder name: " folder_name

if [ ! -d "$folder_name" ]; then
  echo "Error: Folder '$folder_name' does not exist."
  exit 1
fi

files=("$folder_name"/*)

for file in "${files[@]}"; do
  filename=$(basename "$file")
  new_filename="draft_$filename"
  mv "$file" "$folder_name/$new_filename"
done

echo "All files renamed successfully."

Output

import os

# Prompt the user for the folder name
folder_name = input("Enter folder name: ")

# Verify the folder exists
if not os.path.isdir(folder_name):
    print(f"Error: Folder '{folder_name}' does not exist.")
    exit(1)

# Get a list of all files in the folder
files = os.listdir(folder_name)

# Rename each file by adding the prefix "draft_"
for filename in files:
    # Construct the new filename with the prefix
    new_filename = f"draft_{filename}"

    # Construct the full paths for the original and new files
    old_path = os.path.join(folder_name, filename)
    new_path = os.path.join(folder_name, new_filename)

    # Rename the file
    os.rename(old_path, new_path)

print("All files renamed successfully.")

9.4 Debug / Review:叫 AI 幫你檢查問題

Demo:檢查 Python 版本有冇問題

Prompt

Review the following Python code and identify any potential bugs or issues:
import os

folder_name = input("Enter folder name: ")

if not os.path.isdir(folder_name):
    print(f"Error: Folder '{folder_name}' does not exist.")
    exit(1)

files = os.listdir(folder_name)

for filename in files:
    new_filename = f"draft_{filename}"

    old_path = os.path.join(folder_name, filename)
    new_path = os.path.join(folder_name, new_filename)

    os.rename(old_path, new_path)

print("All files renamed successfully.")

Output

The code looks mostly correct, but here are some potential issues and improvements:

1. **Renaming Directories**: `os.listdir()` returns both files and directories. If there are subfolders, `os.rename()` will rename them too. You might want to check `os.path.isfile(old_path)` before renaming.

2. **Name Collisions**: If a file already starts with `"draft_"`, the script will rename it again (e.g., `"draft_draft_file.txt"`). You may want to skip files that already have the prefix.

3. **Permission Errors**: If the script doesn't have permission to rename a file, it will raise an exception. Consider wrapping `os.rename()` in a try/except block.

4. **Hidden/System Files**: Depending on the environment, hidden/system files may be included and could cause unexpected behavior.

10|Prompt 用變數(Variables):令一個 Prompt 可以重用

白皮書提醒:如果你成日要改少少內容(例如姓名、產品名、地點),你可以用「變數」概念,令 Prompt 更易維護、更易改。

Demo:用變數寫 Prompt 模板

Prompt

When writing a prompt, use a variable. Variables can save you time and effort by allowing you to reuse and customize prompts quickly. For example:

Prompt:
Write a short product description for {product_name}. The target audience is {target_audience}. The tone should be {tone}. Limit to {word_count} words.

Output

Example filled-in prompt:
Write a short product description for "Noise-Cancelling Wireless Headphones". The target audience is "busy professionals". The tone should be "confident and friendly". Limit to 60 words.

11|Best Practices(最佳實踐):白皮書的「最重要清單」

白皮書最後有一段 Best Practices,重點其實好易明:

  • 清楚講任務(做咩、輸出乜格式)
  • 需要就俾例子(One-shot / Few-shot)
  • 用 System prompt 控制格式(JSON / uppercase / 只回答案)
  • 推理題要叫佢 step by step
  • 大型任務先拆細再做(Step-back)
  • 記錄你用過的 Prompt 版本(方便再用 / 再改)

12|附錄:Prompt 設計紀錄模板(可用作團隊 SOP)

白皮書提供一個「Prompt 設計紀錄表」,方便你做版本管理(尤其係團隊用 AI、或者你要重複迭代時超有用)。

Demo:Prompt 設計模板

Prompt

Name: [name and version of your prompt]
Goal: [One sentence explaining what the prompt should do]
Model: [name of the model]
Temperature: [value]
Token Limit: [value]
Top-K: [value]
Top-P: [value]
Prompt: [the full prompt]
Output: [example output]

Output

(Use this table as a template to document and iterate your prompts.)

結語:你唔需要識複雜技術,都可以用到提示工程

你唔一定要懂 token、sampling、temperature。
但你要懂一樣嘢:

AI 係靠「你點問」去決定「點答」。

而白皮書示範的所有技巧,其實都係圍繞同一件事:

  • 你想要更穩定 → 加規則(System)
  • 你想要更像某種風格 → 指定角色(Role)
  • 你想要更貼合場景 → 加背景(Context)
  • 你想要更準確推理 → 叫佢 step-by-step(CoT)
  • 你想要更像作品流程 → 先拆解再生成(Step-back)

追蹤以下平台,獲得最新AI資訊:
Facebook: https://www.facebook.com/drjackeiwong/
Instagram: https://www.instagram.com/drjackeiwong/
Threads: https://www.threads.net/@drjackeiwong/
YouTube: https://www.youtube.com/@drjackeiwong/
Website: https://drjackeiwong.com/

Dr. Jackei Wong

擁有超過15年的人工智能研究及教學經驗,我結合學術理論與實際應用,設計專業的AI學習體驗。無論是生成式AI、數據分析,還是日常工作的AI應用,我都會以簡單易懂的方式引導您深入了解,讓您快速上手技術,應對數碼化時代的挑戰。

喜歡請分享