Mastering Prompt Engineering: History, Techniques, and Real-World Applications

This article explains what Prompt Engineering is, traces its evolution from early NLP commands to modern adaptive and multimodal prompting, details core techniques such as Zero‑shot, Chain‑of‑Thought, Auto‑CoT, and reduction of hallucinations, and showcases a logistics case study using various prompting strategies.

JD Cloud Developers
JD Cloud Developers
JD Cloud Developers
Mastering Prompt Engineering: History, Techniques, and Real-World Applications

What Is Prompt Engineering?

Prompt Engineering designs and optimizes the "prompts" or instructions given to AI assistants so that the model understands the task clearly and provides useful responses.

Main aspects of Prompt Engineering:

Clarify the goal: what task the AI should complete.

Design prompts: concise, clear, and containing all necessary information.

Iterate and test: continuously adjust prompts to improve results.

Handle unexpected outputs: anticipate and devise strategies for out‑of‑scope answers.

How Prompt Engineering Emerged

Early stage (pre‑2017)

Basic commands: simple keyword matching and rule‑based systems.

Template Q&A: strict template matching required for responses.

Initial exploration (2017‑2018)

Seq2Seq models: improved input‑output mapping but still needed clear instructions.

Pre‑trained models: GPT‑1 introduced, still required explicit prompts.

Rapid development (2019‑2020)

GPT‑2 release sparked interest in prompt design.

BERT and other models enabled bidirectional understanding, influencing prompt strategies.

Maturation (2020‑2021)

GPT‑3 release with few‑shot and zero‑shot capabilities made Prompt Engineering essential.

Technical evolution (2021‑2023)

Prompt Tuning: adjusting prompt parameters to boost performance.

Automation tools: frameworks that generate and test prompts quickly.

Domain‑specific optimization: tailoring prompts for fields like medicine, law, education.

Modern stage (2024+)

Adaptive prompt generation: models dynamically adjust prompts based on context.

Multimodal prompts: combine text, images, audio for richer interactions.

Human‑AI collaborative optimization: iterative feedback loops improve efficiency.

Prompt Engineering Techniques

1) Zero‑shot and Few‑shot

Zero‑shot: give task and goal directly, adjusting format and parameters as needed.

Few‑shot: provide a few examples; careful example selection is crucial to avoid bias.

Basic parameters:

temperature: controls randomness (0‑1)</code><code>max_tokens: maximum output length</code><code>top_p: cumulative probability sampling</code><code>n=1: number of responses</code><code>stop=None: no stop condition</code><code>presence_penalty: discourage repetition</code><code>frequency_penalty: discourage frequent tokens

2) Reasoning and Logic

Techniques such as Chain‑of‑Thought (CoT), Automatic CoT, Self‑Consistency, and Logical CoT guide models to produce step‑by‑step reasoning, improving accuracy on complex tasks.

3) Reducing Hallucinations

Methods like Retrieval‑Augmented Generation (RAG), ReAct Prompting, and Chain‑of‑Verification (CoVe) combine external knowledge retrieval and self‑checking to limit inaccurate or fabricated outputs.

4) Fine‑Tuning and Optimization

Automatic Prompt Engineer (APE) generates candidate prompts, scores them, selects high‑scoring ones, optionally resamples, and finalizes the best prompt.

5) Other Techniques

Chain‑of‑Code (CoC): transforms tasks into pseudo‑code for better logical reasoning.

Contrastive CoT (CCoT): presents both correct and incorrect reasoning examples.

EmotionPrompt: injects emotional cues to guide model tone.

Rephrase and Respond (RaR): reformulates questions for clearer understanding.

Application Case: JD Logistics Item‑Type Classification

Project Background

In JD Logistics, incorrect item‑type labeling for large goods causes revenue loss and customer complaints. A large‑language‑model‑based system was built to recognize item‑type anomalies and provide recommendations, especially for air‑conditioner SKUs.

Example Prompting Strategies

Various prompting methods (Zero‑shot, Few‑shot, CoT, Auto‑CoT, Self‑Consistency) were tested on a dataset of 7 fields (e.g., goods_code, goods_name, weight, item_type). Accuracy improved from 44.44% (Zero‑shot) to 77.78% (Auto‑CoT).

Sample Python code for basic GPT call:

def classify_product(row, rules_text):
    try:
        client = OpenAI(api_key=os.environ["OPENAI_API_KEY"], base_url=os.environ["OPENAI_API_BASE"])
        description = f"商品编码:{row['goods_code']},描述:{row['goods_name']},重量:{row['weigth']}。"
        system_message = "你是物流行业的一位专家,请基于规则和商品描述,仅输出该商品的件型,不要输出其他任何信息。"
        user_message = f"规则:
{rules_text}
商品描述:{description}
"
        response = client.chat.completions.create(
            model="gpt-4-1106-preview",
            messages=[{"role": "system", "content": system_message}, {"role": "user", "content": user_message}],
            temperature=0,
            max_tokens=6,
            top_p=0.1,
            n=1
        )
        return response.choices[0].message.content.strip()
    except Exception as e:
        return str(e)

Prompts were refined to include examples and step‑by‑step logic, leading to higher precision in item‑type determination.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

AILLMPrompt engineeringchain-of-thoughtPrompt Design
JD Cloud Developers
Written by

JD Cloud Developers

JD Cloud Developers (Developer of JD Technology) is a JD Technology Group platform offering technical sharing and communication for AI, cloud computing, IoT and related developers. It publishes JD product technical information, industry content, and tech event news. Embrace technology and partner with developers to envision the future.

0 followers
Reader feedback

How this landed with the community

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.