Prompt Engineering and In-Context Learning: Foundations, Technique Map, and Practical Workflows

Hyacehila

Prompt is an interface, not a spell.

I have previously divided the guidelines on indicative learning, on indicative engineering and on Google. It follows that three of them are actually discussing different aspects of the same matter: the basic articles describe how to write, the synthesis collects a large number of methodological names, and the Guide to Practice tells ordinary users how to communicate their mandates clearly. When separated, the basics, the technological spectrum and the scenes were broken.

This article begins with a simple judgment:Prompt is the input interface for the current reasoning process of the model. It can change the information, mission expression and output constraints that the model sees, but it does not modify parameters or add to the knowledge and capabilities that the model has not learned. Thinking about this border clearly makes a lot of "tips" no longer mysterious.

A usable tip usually contains five types of information:

  1. Tasks: What action the model is going to make, what the success criteria are.
  2. Input: Data, issues or materials to be addressed in this session.
  3. Context: Background, reference documents and constraints required to complete the task.
  4. Example:: the input-output relationship that the model is expected to imitate.
  5. Output Contract: Format, length, fields, audience and unworkable.

They do not need to appear in every instance. A request for “translation of this sentence into English” had been sufficient for tasks and inputs; a result of an analysis to be submitted to the process for consumption would require clearer field, type and failure processing. The length of the hint does not mean that the message is more adequate, and the key is whether each paragraph really affects the mandate.

How do you write a basic tip?

Google. Gemini for Workspace Prompting Guide The organization of the office scenes is based on the four components: Persona (role), Task, Context, and Format. The framework is practical, but Persona is not an obligatory one; in many missions, it is more useful to identify audiences, materials and criteria for judgement than to require models to “play top-level experts”.

Here is a skeleton that is more suitable for a technical mission:

任务:根据给定事故记录,整理一份故障复盘摘要。

输入: <incident> {{事故记录}} </incident>

上下文与边界:

  • 读者是参与值班的后端工程师。
  • 只使用记录中出现的事实;无法确认的内容标记为“待核实”。
  • 区分直接原因、促成因素和后续风险。

输出:

  1. 事件时间线
  2. 影响范围
  3. 原因分析
  4. 已完成和待完成的行动项

There's no special excuse. The labels are used to separate materials, and the project symbol clearly sets out the criteria for judgement, and the output part gives the model how the results are used. If the record is long, please also indicate which fields are most important, which sources are allowed to be cited and how they should be returned if the material is insufficient.

Write action, then a correction.

The “analysis of the report” remains broad. The analysis can refer to generalization, risk identification, numerical reconciliation, comparative versions, or policy recommendations. A better job description will use specific actions:

  • (a) Extracting the three key assumptions in the report and quoting the corresponding paragraphs;
  • Comparison of cost, dependence and failure patterns of the two programmes;
  • (a) Identify inconsistencies between conclusions and table data;
  • Rewriting the original text to a reader who is not aware of the background does not add new facts.

The clearer the verb, the easier the subsequent assessment. Conversely, if even people fail to say what is good, continuing the role, tone and “think carefully” will not normally save the task.

Separate the material from the instructions.

Long documents, user input, code and web content should preferably be placed in a clear partition. This allows both the model to distinguish between “directions to be followed” and “data to be processed” and the program to replace variables.

The separator is not a secure boundary. External material may contain text that conflicts with the system ' s target, and genuine applications still require privileges, content filters and protection of prompt. The structure of the alert can only reduce ambiguity and cannot replace the boundaries of trust at the system level.

Output format to be consistent with downstream

A visible result may require a title, table or brief conclusion; the result given to the program should define the field, type, number and missing value. Only writing "return to JSON" in the prompt may still produce an illegitimate output. When there is a hard-on format correctness, require JSON Schema, function call or restricted decoding, as detailedLarge Model Structured Output and Limited Decoding Technologies

Context learning: an example is also a temporary training signal

Context learning (In-Context Learning, ICL) allows models to recognize tasks without updating model parameters by commands and examples in the current context. Only the job description is often called zero-shot; one-shot or new-shot is added to one-shot or one or more examples of input outputs.

It looks like “field teaching”, but the model does not really complete the gradient update. The example is only part of the current sequence and will not be automatically retained after leaving this context. This feature makes ICL well suited to fast-adaptation formats and labels, and it is also limited by context length, illustrative order and the model ' s own capabilities.

Example selection is more important than the number of examples

The Few-shot example must satisfy at least three things at once:

  • Use the same field and output format as the actual input;
  • Covering easily confused borders, not just the simplest formal cases;
  • The answer is correct in itself, and the way in which it is interpreted is consistent with the final task.

If emotional classification is given to only three obvious positive samples, the model does not learn how to deal with irony, mixed evaluation or neutral statements. The more examples, the more they are, the more space they actually enter, and the more chance they can be for models to imitate random details. A more stable approach would be to identify the types of failure from the authentication collection, which would be supplemented by examples of those types.

The order of examples will also affect the outcome. The distribution of labels, recent examples and presentation may all be biased. Where stability is needed, the order of the evaluation can be changed rather than tested for a single ranking that appears to be good.

RAG does not equal Few-shot

The Few-shot example tells the model "how this task is done " ; the document that RAG retrieves usually tells the model " what the answer should be based on." Both place information in context, but assume different roles. The RAG also contains engineering issues such as cut-offs, indexing, retrieval, reordering, citation and permissions, which cannot be reduced to “a few additional sections of information”.

The context window is not a warehouse that can be filled with randomly. The more material the information is, the more noise the information is. How to select, compress, isolate and update the context has evolved from a single prompt writing to a separate context engineering issue, see"Context is All You Need: Context Project for Smart Bodies"

Technological mapping: first, by problem

There's a lot of paper on the subject. Chain-of-XI'm sorry. Some methods propose reusable structures, some are only built on specific data sets and models, and others are closer to the reasoning system or the Agent framework. Instead of abbreviated memory, ask what it is trying to change.

graph TD
    A["Prompt 技术"] --> B["任务表达与示例学习"]
    A --> C["推理、搜索与分解"]
    A --> D["检索、工具与验证"]
    A --> E["自动生成与迭代优化"]
    B --> B1["Zero/Few-shot · Persona · Step-Back"]
    C --> C1["CoT · Self-Consistency · ToT/GoT · PoT"]
    D --> D1["RAG · ReAct · CoVe · Chain-of-Note"]
    E --> E1["Self-Refine · APE · OPRO · Active-Prompting"]

Mission expression and example learning

Such approaches primarily improve how mandates are expressed. Zero-shot and few-shot decide whether to give examples; roll, scene, format and separator reduce semantic ambiguity; and Refrase and Repond, Step-Back, etc., rewriting questions or abstracting high-level principles before processing specific requests.

They are best suited to situations where the mission ' s intent is not clear, where the presentation is significantly altered or where the output is unstable. If problems arise from lack of knowledge, the inaccessibility of tools or inadequate modelling capacity, continuing to improve the same text usually only leads to more fluid errors.

Decompose, search and decompose.

Chain-of-Thought Insert intermediate decomposition steps in the examples to allow models to imitate the process from question to answer;Zero-shot-CoT Proof of simple step-by-step reasoning directives may also improve some of the tasks. They have implications for mathematics, symbols and multi-step reasoning, but the benefits depend on models, tasks and assessment methods. Simple factual extraction or fixed classification does not require Mr. S.S. to form a large line of reasoning.

In the product, I am more concerned with verifiable intermediates than with the need for models to show all the “thinking processes”. The model can be used to list the evidence used, give the computation, generate the operational codes or return the checklist. This would be more useful than a reasonable but unreconciled interpretation, both to aid in debugging.

Self-Consistency Samp multiple reasoning paths to the same question, and then aggregate the final answer. It is a matter of extra reasoning costs for stability and is suitable for a task where the answer can be consolidated and voted upon. If the output is an open formula or a long text, it is often difficult to define what is called “most answers”.

Tree of Thoughts and Graph of Thoughts Extending the single chain of reasoning to a search structure: generate candidates, evaluate status, retain or retreat and continue. It's not just a prompt, it's a design of the reasoning controller. There is no status representation, evaluation function and search budget, and simply requiring the model to “use the think tree” usually produces only one tree description.

Program of Thoughts Give the calculation to the program interpreter,Chain of Draft . Compress the middle step to reduce the cost of the token. They remind each other that verifiable calculations need not be based solely on linguistic models, and that the reasoning text is not as reliable as it is long.

Search, Tool Call and Results Validation

RAG (a) Retrieving external material before generating responses based on the material;ReAct The model is staggered between reasoning and action and can be searched, called upon, read and processed. These methods reduce the pressure for the model to answer questions by using only parameter memory and introduce new failure points: retrieval may miss evidence, tools may return errors, and models may misinterpret observations.

Chain-of-Verification The model is prepared to draft the answers, then to generate validation questions and independently examine them. It is appropriate to disassembly a specific factual answer, but “let one model examine itself” does not automatically amount to independent evidence. More reliable validation is obtained from the original document, rules, tests, calculator or another data path.

If the task requires strict grammar, the validation should preferably occur during the token generation, rather than pray for a successful resolution after the entire text has been written. This is the line between restricted decode and common tip projects. Prompt describes intent, code decoder semantics, both of which can be used together, but should not be impersonated against each other.

Auto-generated, iterative and self-adaptation tips

Self-Refine Use of the `revenue-revision-change' cycle improvement results;APE and OPRO The model is then used to generate a candidate command, which is then selected or iteratively by the task performance. Active-Prompting gives preference to the unsettled sample of the model for labelling, while Information-imptive Prompting is a hint for different input adjustments.

Such methods are indispensable to the assessment set. One case alone can easily be seen as a reminder of improvement. The candidate prompt should be compared with model decoded parameters, recording accuracy, format pass rate, cost and type of failure in the data that cover the real distribution. If no duplicate rating is available, automatic optimization is only an automatic rewrite.

Site practice: from generation round to searchable workflow

Google's guide covers the scenes of administration, communication, marketing, project management and sales. The specific occupation changes and the pattern behind the writing is stable: it is given materials, it describes the action, it defines the audience and the format, and it is then continued to be modified on the basis of results. Only four common categories of tasks are retained below.

Writing and summary

任务:把下面的技术说明改写成发布说明。

读者:已经使用旧版本、但不了解内部实现的开发者。

要求:

  • 先说明用户能观察到的变化,再说明迁移注意事项。
  • 保留版本号、命令和兼容性限定。
  • 不写“重大升级”“全面赋能”等宣传性结论。
  • 控制在 400 字以内。

原始材料: <source> {{技术说明}} </source>

The design focus is not “you are a professional technical writer”, but readers, authenticity requirements and the use of expressions is disabled. Where the source material lacks compatible information, the model should identify gaps rather than supplement an apparently reasonable migration proposal.

Information extraction and structured results

从合同文本中提取以下字段:合同主体、生效日期、终止日期、自动续约、付款周期。

规则:

  • 字段没有出现时返回 null。
  • 日期统一为 YYYY-MM-DD;原文无法确定具体日期时保留原始表达。
  • 每个非空字段附带原文证据。
  • 不根据常见合同惯例推断。

返回字段: parties, effective_date, termination_date, auto_renewal, payment_cycle, evidence

The key to such a reminder is missing values and evidence, not a sentence “Please extract accurately”. If the result is directly entered, the schema verification and restricted decode should also be used; Prompt is responsible for semantics and the program is responsible for rejecting the unlawful object.

Analysis and planning

根据提供的需求、人员和截止日期,生成一份两周实施计划。

先列出你从材料中确认的约束,再输出任务依赖图和每日计划。 不要假设未提供的人员可用性。若计划无法在截止日期内完成,指出最小缺口并给出两个调整方案。

The planning mission is most afraid that the model will be used to provide complete answers. It is more reliable to list what is not feasible to report in a binding and visible manner than to require “a comprehensive plan”. Complex schemes also require calendars, code libraries, worksheets or solvers, which cannot be stopped in a single natural language.

Multi-temporal

The multi-round dialogue is appropriate to gradually reduce the problem, but it is not always the model that will remember what has been said. Each round of modifications should be expressly reserved for items and changes, such as:

保留上一版的事实、引用和章节顺序,只修改下面三点:
1. 把开头缩短到两段。
2. 将第二节的示例替换为给定的新案例。
3. 删除没有来源的效果判断。

修改后附一份变更清单,不要改动其他部分。

When the dialogue has accumulated a large amount of scrap and conflicting demands, it is usually more stable to organize a new mission statement than to continue adding a “reform”. This is why context projects are officially operational with respect to both content and reset.

Google Official English Handbook is directly accessible Gemini for Workspace Prompting GuideI'm sorry. We have a copy of the package. Gemini Bilingual Handbook of Phrases, which is appropriate for quick viewing of the original scene example.

Prompt solves what, doesn't solve what

Problem Prompt, what can you do? What else can I get you?
The mission is not clear. Additional action, boundary, examples and success criteria Sample of real user needs and assessments
Lack of current facts Tell the model to be based only on the response to the given material Retrieving, database, search and reference
Complex calculations are easily incorrect. Requires the generation of formulae, codes or check steps Calculators, interpreters, tests and certifiers
JSON often parses failed Description field, type and missing value Schema, function call or restricted decode
Forgetting constraints in long missions Restatement of key rules, compression context Context management、memory、checkpoint
The model doesn't even know how to do it. Provide a few examples for ad hoc adaptation More appropriate models, SFTs, tools or process re-engineering

The most comfortable location for the project is to convert an already available and assessable task. It can reduce ambiguity and cannot replace data, training, retrieval, tools and procedural constraints. Knowing when to stop prompt is often more important than learning another acronym.

Method Index

The table below retains the name of the method that appeared in the previous synthesis, but does not assign a short, repetitive chapter to each. Many methods have clear mission boundaries and the results of the papers rely on the models and data sets used at the time. Read the original paper and code before using them, and not just by name, to judge whether it fits the current system.

Methodology Category One word. Source material
Zero-shot / Few-shot Basic expression Show the model to recognize new tasks by job description or a few examples GPT-3
Chain-of-Thought(CoT) Inference Insert intermediate delineation steps in the illustrative examples Wei et al.
Zero-shot-CoT Inference Trigger intermediate steps with simple step-by-step instructions Kojima et al.
Auto-CoT Auto-optimize Cluster problems and automatically generate CTT examples Zhang et al.
Self-Consistency Decoded and decoded Samp multiple reasoning paths to aggregate answers Wang et al.
LogiCoT Training and reasoning Learning Logic through institution learning COT and adding to the check process Zhao et al.
Chain-of-Symbol(CoS) Inference A compact symbol for space relations and planning steps Hu et al.
Tree of Thoughts(ToT) Search Generate, evaluate and withdraw candidate thinking in tree structures Yao et al.
Graph of Thoughts(GoT) Search Combine, aggregate and improve the middle lines with graphics Besta et al.
System 2 Attention(S2A) Context Process Rewrite the context to reduce the impact of unrelated information on the answers Weston & Sukhbaatar
Thread of Thought(ThoT) Context Process Answers after a summary of long or confusing context subparagraphs Zhou et al.
Chain-of-Table Special reasoning. Complete table asking through continuous table operations Answer Wang et al.
Self-Refine Auto-optimize Use model-generated feedback loop to modify the first draft Madaan et al.
Code Prompting The reasoning suggests that Recast the issue of natural language into code and delineate it as a subsidiary condition. Madaan et al.
ECHO Auto-optimize COT example of cluster and repeatedly coordinated automatically generated Self-Harmonized CoT
Instance-adaptive Prompting(IAP) Self-adaptation Select or reorganize zero-shot COT tips from the current instance Zhang et al.
Layer-of-Thoughts(LoT) Specialized search Organize candidate screens for legal searches at a binding level Choose Choi et al.
Narrative-of-Thought(NoT) Special reasoning. The narrative structure and procedures are used to indicate the time reasoning of the processing Kim et al.
Buffer of Thoughts(BoT) Logical reuse Save and retrieve reusable high-level think templates Yang et al.
CD-CoT Luo-Boo-Boo-Boo-Boo-Boo-Boo-Boo-Boo-Boo-Boo-Boo-Boo-Boo-Boo-Boo-Boo-Boo-Boo-Boo-Boo-Boo-Boo-Boo-Boo-Boo-Boo-Boo-Boo-Boo-Boo-Boo-Boo-Boo-Boo-Boo-Boo-Boo-Boo-Boo-Boo-Boo-Boo-Boo-Boo-Boo-Boo-Boo-Boo-Boo-Boo-Boo-Boo-Boo-Boo-Boo-Boo-Boo-Boo-Boo-Boo-Boo-Boo-Boo-Boo-Boo-Boo-Boo-Boo-Boo-Boo-Boo-Boo-Boo-Boo-Boo-Boo-Boo-Boo-B-B-B-B-B-B-B-B-B-B Rewrite, select and vote on the Noise CTT Example Zhou et al.
Chain of Draft(CoD) Efficient reasoning Use a very short middle step to lower the reasoning token and delay Xu et al.
Retrieval-Augmented Generation(RAG) Search Once you have access to external evidence, you can generate answers. Lewis et al.
ReAct Tool Call Let reasoning, action and environmental observation intersect. Yao et al.
Chain-of-Verification(CoVe) Authentication Generate validation questions and independent answers for first drafts Dhuliawala et al.
Chain-of-Note(CoN) Search and Validation Generate notes for retrieval of documents, filter unrelated or conflicting materials Yu et al.
Chain-of-Knowledge(CoK) Knowledge integration Phased preparation, acquisition and adaptation of external knowledge Li et al.
Scratchpad Prompting Inference Generate any intermediate calculation before the final answer Arguments Nye et al.
Program of Thoughts(PoT) Tools and reasoning Use the program to calculate and give it to the interpreter to execute Chen et al.
Structured CoT(SCoT) Code Generation Planning code by order, branch and circular structure Li et al.
Chain of Code(CoC) Code reasoning Generate pseudocodes and execute them with language model enhanced interpreter Li et al.
Active-Prompting Auto-optimize Prioritize the most uncertain issue of the model to be marked CTT Diao et al.
Automatic Prompt Engineer(APE) Auto-optimize Generate candidate commands and search for task performance tips Zhou et al.
Automatic Reasoning and Tool-use(ART) Tool Call Retrieving examples from the task library and automatically combining reasoning and tool steps Paranjape et al.
Contrastive CoT(CCoT) Example Learning And provide examples of correct and erroneous reasoning as a comparison Chia et al.
EmotionPrompt Job expression Add emotional irritation to the hint and measure mission performance Li et al.
Optimization by PROmpting(OPRO) Auto-optimize Let LLM continue to offer his solution based on his historical candidacy and scores. Yang et al.
Rephrase and Respond(RaR) Job expression Questions are rewritten and extended before the final answer is generated Deng et al.
Step-Back Prompting Job expression First, abstract high-level concepts and principles, then specific examples. Zheng et al.

References

Some of these methods have become generic engineering components, while others are still experimental designs in specific papers. The technical catalogue is intended to help locate, not to imply that all methods should be entered into the same programt. In the face of specific mandates, starting with clear mandates, reliable context and enforceable validation, most of the problems are usually resolved.

  • Title: Prompt Engineering and In-Context Learning: Foundations, Technique Map, and Practical Workflows
  • Author: Hyacehila
  • Created at : 2024-09-20 12:00:00
  • Link: https://hyacehila.github.io//blog/2024/09/20/prompt-engineering-and-in-context-learning/
  • License: This work is licensed under CC BY-NC-SA 4.0.
Comments