Artificial Intelligence 29 min read

Prompt Engineering: Definitions, Frameworks, Principles, and Advanced Techniques

The guide defines prompts as structured queries that unlock large‑language‑model abilities, outlines five core frameworks (RTF, Chain‑of‑Thought, RISEN, RODES, Density‑Chain), presents two key principles—clear, delimited instructions and explicit reasoning steps—to reduce hallucinations, and surveys advanced techniques such as zero‑shot, few‑shot, RAG, Tree‑of‑Thought and automatic prompt engineering.

Tencent Technical Engineering
Tencent Technical Engineering
Tencent Technical Engineering
Prompt Engineering: Definitions, Frameworks, Principles, and Advanced Techniques

Amid the digital wave, large AI models have become pivotal due to their natural language processing and interactive capabilities. By crafting well‑designed prompts, they can significantly improve efficiency in customer service, intelligent assistants, and many other business scenarios. This note, compiled after studying courses on prompting by Andrew Ng and other experts, delves into the definition, structure, principles, and technical foundations of prompts to help readers harness large models effectively.

Section 1: Prompt Definition and Basic Framework

A prompt is a query that "tips" a large language model to activate specific abilities for solving real‑world problems. Early terms such as "input form" or "input template" evolved into "prompt" because it accurately reflects the role of invoking model capabilities. Prompts act like keys, unlocking abilities such as complex text understanding, summarization, content generation, and logical reasoning that were learned during pre‑training.

1.1 Prompt Elements

• Instruction : the specific task or command for the model. • Context : external or additional information that guides the model. • Input Data : the user‑provided content or question. • Output Specification : the desired type or format of the answer.

1.2 Five Major Prompt Frameworks

RTF Framework (Role‑Task‑Format)

Simple and universal: specify a role (e.g., programmer, analyst), a task, and the output format (table, Markdown, English, etc.).

Chain‑of‑Thought (CoT) Prompting

Guide the model to reason step‑by‑step by appending "let's think step by step" at the end of the prompt.

# 数据源(与指令区分)
user_datasource = """XXX……"""

prompt1 = """分析一下在人工客服服务场景下,'''{user_datasource}'''中客户有哪些诉求。用一句话概括。"""
prompt2 = """分析一下在人工客服服务场景下,'''{user_datasource}'''中客户有哪些诉求。用一句话概括。让我们逐步思考。"""

# 模型输出结果
output1:在人工客服服务场景下,客户主要诉求为:微信账号存在安全风险导致无法添加好友、单点拦截、下载安装微信出现问题等,寻求客服协助解决问题。
output2:在人工客服服务场景下,客户主要诉求为:微信账号存在安全风险导致无法添加好友,以及因违规行为被限制登录,客户希望客服能够尽快处理这些问题。

# 分析结果
output1中的”单点拦截”并不是用户的诉求,而output2显然更加正确

RISEN Framework

Components: Role, Instructions, Steps, End Goal, Narrowing (constraints). Suitable for tasks with explicit constraints or guided directives.

RODES Framework

Components: Role, Objective, Details, Examples, Sense Check.

Density‑Chain Prompting

A recursive prompting technique that yields denser, more understandable summaries, especially useful for summarization tasks.

Section 2: Two Core Principles for Efficient Prompts

Principle 1: Write Clear and Specific Instructions

Use delimiters (section titles, triple quotes, triple dashes, angle brackets, XML tags) to separate instruction from input, preventing confusion.

product_description = f"""这是一款全新的智能手表,具备心率监测、睡眠追踪等健康功能,还支持多种运动模式记录,拥有高清显示屏和长达7天的续航能力。"""
prompt = f"""请总结以下产品描述:'''{product_description}'''"""

user_comment = f"""这款手机的拍照效果真的太棒了,色彩还原度高,夜景模式也很出色,唯一不足的是电池续航有点短。"""
prompt = f"""分析以下用户评论的情感倾向:''' {user_comment}''' """

Require structured output (JSON, HTML) to facilitate downstream processing.

prompt = "请以json格式列出每个nodeType所体现的用户诉求、客服方案。每一个json-value不超过20个字"

# 数据源(与指令区分)
user_datasource = """XXX……"""

# 模型输出
{
  "IVR": {"用户诉求": "微信使用问题求助", "客服方案": "引导正常使用或自助处理"},
  "ASYNC": {"用户诉求": "账号封禁等相关申诉", "客服方案": "按规则处理或引导自助"},
  "AI": {"用户诉求": "支付相关问题咨询", "客服方案": "要求用户详细描述问题"}
}

Principle 2: Give the Model Sufficient Thinking Time

Explicitly list the steps required to solve a task, encouraging thorough reasoning before reaching a conclusion.

poem = "床前明月光,疑是地上霜。举头望明月,低头思故乡。"
prompt = f"请按照“诗歌主题 - 主要意象 - 表达情感”的格式分析这首诗:{poem}"
# 模型输出
思乡之情 - 明月 - 对故乡的深切思念

Section 3: Limitations and Mitigation Strategies

Large models can hallucinate—producing plausible but incorrect information—because they cannot memorize all knowledge and lack clear boundaries. To combat hallucinations, require the model to cite sources from the provided text before answering.

text = """1861年,美国爆发了南北战争,这场战争是美国历史上的重要转折点,它主要围绕奴隶制的存废问题展开,北方主张废除奴隶制,南方则坚持保留。最终北方取得了胜利,为美国的工业化发展铺平了道路。"""
prompt = f"请从上述文本中找出相关信息,回答南北战争主要围绕什么问题展开?"
# 模型输出
南北战争主要围绕奴隶制的存废问题展开,北方主张废除奴隶制,南方则坚持保留。

Section 4: Advanced Prompt Techniques

Zero‑Shot Prompting, Few‑Shot Prompting, Chain‑of‑Thought, Self‑Consistency, Generated Knowledge Prompting, Prompt Chaining, Tree‑of‑Thought, Retrieval‑Augmented Generation (RAG), Automatic Reasoning and Tool Use (ART), Automatic Prompt Engineer (APE), Active‑Prompt, Directional Stimulus Prompting, PAL (Program‑Assisted LLM), ReAct, Reflexion, etc., are introduced with concise code examples illustrating their usage.

# Zero‑Shot example
prompt = "判断此文本的情感倾向为积极、消极或中性:这部电影情节紧凑,特效惊人。情感:"
# Few‑Shot example
prompt = """“whatpu”是坦桑尼亚的一种小型毛茸茸的动物。一个使用 whatpu 这个词的句子是:我们在非洲旅行时看到了这些非常可爱的whatpus。"""
# RAG example
question = "谁是首次登上月球的人?"
documents = retrieve_documents(question)
prompt = "根据以下文档回答问题:" + str(documents) + " 问题是:" + question
answer = generate_answer(prompt)

The document concludes with a glossary of terms, a FAQ section, and visual illustrations, reinforcing the comprehensive nature of prompt engineering.

AIprompt engineeringLarge Language ModelsRetrieval-Augmented GenerationChain-of-ThoughtFew-Shot PromptingPrompt Frameworks
Tencent Technical Engineering
Written by

Tencent Technical Engineering

Official account of Tencent Technology. A platform for publishing and analyzing Tencent's technological innovations and cutting-edge developments.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.