Master Prompt Engineering: Frameworks, Strategies, and Real‑World Examples for Large Language Models

This comprehensive guide explains what prompts are, outlines essential prompt components and multiple engineering frameworks, presents practical strategies for crafting clear and structured prompts, addresses model limitations such as hallucinations, and showcases a wide range of advanced prompting techniques with code examples.

dbaplus Community
dbaplus Community
dbaplus Community
Master Prompt Engineering: Frameworks, Strategies, and Real‑World Examples for Large Language Models

Prompt Definition and Basic Framework

A prompt is the query that activates a specific capability of a large language model (LLM). During pre‑training the model acquires general knowledge; the prompt acts as a key that unlocks abilities such as text understanding, summarisation, generation, and logical reasoning.

Basic Prompt Structure

A well‑formed prompt usually contains four elements:

Instruction: the task you want the model to perform.

Context: any external information that guides the model.

Input Data: the actual content or question.

Output Specification: the desired format of the answer.

RTF Framework (Role‑Task‑Format)

Simple and universal:

R – Role: assign a fixed role (e.g., programmer, data analyst).

T – Task: describe the task.

F – Format: specify the output format (table, Markdown, plain text, etc.).

Chain‑of‑Thought Prompt

Appending “let’s think step by step” forces the model to reason gradually, which improves performance on complex or logical tasks.

# Data source (separate from instruction)
user_datasource = """XXX…"""

prompt1 = """Analyze the customer requests in the following service log: '''{user_datasource}''' and summarise in one sentence."""
prompt2 = """Analyze the customer requests in the following service log: '''{user_datasource}''' and summarise in one sentence. Let’s think step by step."""

# Model outputs
output1: "Customers mainly need help with WeChat account security, single‑point interception, and installation issues."
output2: "Customers mainly need help with WeChat account security and account restrictions; they seek prompt assistance."

RISEN Framework

Extends the prompt to five parts:

R – Role

I – Instructions

S – Steps

E – End Goal

N – Narrowing (Constraints)

Useful for tasks with explicit constraints such as writing a blog post or a business plan.

RODES Framework

Provides a comprehensive template: Role, Objective, Details, Examples, Sense‑check.

Density‑Chain Prompt

Introduced by researchers at Salesforce, MIT and Columbia, this recursive prompt generates increasingly refined outputs, producing denser and more understandable summaries.

Core Principles for Effective Prompts

Write Clear and Specific Instructions

Explicit instructions reduce ambiguity and improve relevance.

Use Delimiters to Separate Sections

product_description = f"""This smartwatch offers heart‑rate monitoring, sleep tracking, multiple sport modes, a high‑resolution display, and up to 7‑day battery life."""
prompt = f"""Summarise the following product description: '''{product_description}'''"""

Require Structured Output

prompt = "Please output a JSON mapping each nodeType to the user request and the suggested service. Each value should be no more than 20 characters."
user_datasource = """XXX…"""

# Expected model output
{
  "IVR": {"User Request": "WeChat usage issue", "Service": "Guide normal use or self‑service"},
  "ASYNC": {"User Request": "Account ban appeal", "Service": "Process according to policy"},
  "AI": {"User Request": "Payment inquiry", "Service": "Ask user for details"}
}

Condition Checking

expression = "5 + 3 - (-2)"
prompt = f"""First check whether all numbers in '{expression}' are positive. If they are, compute the result; otherwise output 'Expression contains non‑positive numbers, cannot compute'."""

# Model output
Expression contains non‑positive numbers, cannot compute

Few‑Shot Prompting

# Translation and sentence creation example
"""
Example 1:
Chinese word: 苹果
Translation: apple
Sentence: I like to eat apples.

Example 2:
Chinese word: 学校
Translation: school
Sentence: I go to school every day.

Example 3:
Chinese word: 图书馆
Translation:
Sentence:
"""

Give the Model Time to Think

# Poetry analysis example
poem = "床前明月光,疑是地上霜。举头望明月,低头思故乡。"
prompt = f"Analyse the poem in the format 'Theme - Main Imagery - Expressed Emotion': {poem}"

# Model output
思乡之情 - 明月 - 对故乡的深切情感

Model Limitations and Hallucination Mitigation

Reduce Hallucinations by Citing Evidence

text = """In 1861 the American Civil War broke out, primarily over the issue of slavery. The North advocated abolition, the South wanted to keep it. The North eventually won, paving the way for industrialisation."""
prompt = "From the above passage, answer: What was the main issue of the Civil War? Cite the relevant sentence."

# Model output
The Civil War mainly revolved around the issue of slavery, as stated: "the war ... primarily over the issue of slavery."

Retrieval‑Augmented Generation (RAG)

question = "Who was the first person to walk on the Moon?"
documents = retrieve_documents(question)
prompt = "Based on the following documents, answer the question: " + str(documents) + " Question: " + question
answer = generate_answer(prompt)

Automatic Reasoning and Tools (ART)

# Compute average apples per person and add 3
prompt = """Calculate the average number of apples per person when 16 apples are divided among 4 people, then add 3. Provide the program steps."""
# Model might generate:
# result = (16 / 4) + 3

Advanced Prompting Techniques

Zero‑Shot Prompting: Directly ask the model without examples.

Few‑Shot Prompting: Supply a few exemplars to teach the pattern.

Chain‑of‑Thought: Show detailed reasoning steps.

Self‑Consistency: Generate multiple reasoning paths and select the most consistent answer.

Generated Knowledge Prompting: First ask the model to produce relevant background knowledge, then answer.

Prompt Chaining: Break a complex task into sub‑prompts, passing intermediate results.

Tree‑of‑Thought (ToT): Explore multiple reasoning branches with search.

Directional Stimulus Prompting: Use a learned “stimulus” prompt to guide downstream generation.

Program‑Assisted Language Model (PAL): Generate executable code to solve a problem.

ReAct: Interleave reasoning and tool‑use actions.

Reflexion: A three‑model loop (actor, evaluator, reflexion) that learns from its mistakes.

Active‑Prompt: Identify high‑uncertainty queries, annotate them, and refine the prompt.

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 engineeringLarge Language Modelsfew-shot promptingprompt frameworks
dbaplus Community
Written by

dbaplus Community

Enterprise-level professional community for Database, BigData, and AIOps. Daily original articles, weekly online tech talks, monthly offline salons, and quarterly XCOPS&DAMS conferences—delivered by industry experts.

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.