What Are the Basic Concepts of Prompt Engineering? A Complete Guide to the DAIR-AI Repository

The basic concepts of prompt engineering include explicit instruction design, LLM hyperparameter configuration (temperature and top_p), standard QA formatting with few-shot examples, and four core prompt elements—instruction, context, input data, and output indicator—that together form a systematic approach to optimizing large language model outputs.

The dair-ai/Prompt-Engineering-Guide repository serves as a comprehensive open-source curriculum for mastering prompt engineering. This guide distills the foundational principles documented in guides/prompts-intro.md and related files, providing developers with actionable patterns to improve LLM outputs through structured communication strategies.

Basic Prompts and the Need for Explicit Instructions

The repository begins with the simplest possible interaction: raw text completion. When you provide a fragment like "The sky is", the model continues based on probabilistic patterns learned during training. However, as documented in guides/prompts-intro.md, this approach often yields unpredictable results because the model lacks task-specific direction.

Transforming Continuation into Task Execution

Adding explicit instructions—such as "Complete the sentence:" before the text fragment—fundamentally changes the model's behavior. This progression from raw completion to instruction-based prompting illustrates the first principle of prompt engineering: clarity of intent produces consistency of output. The guide emphasizes that even minimal structural changes can significantly improve result quality.

LLM Settings: Temperature and Top_p Sampling

Understanding model behavior requires mastery of two critical hyperparameters discussed in the repository's introduction section. These settings control the stochastic nature of text generation and directly interact with your prompt design.

Controlling Determinism vs. Creativity

Temperature scaling controls randomness in token selection. Lower values (e.g., 0.1-0.3) produce deterministic, focused outputs suitable for factual extraction or code generation. Higher values (e.g., 0.7-1.0) increase creativity and variability for brainstorming or creative writing tasks.

Top_p (nucleus sampling) limits the probability mass considered for each token generation. Lower values restrict the model to high-probability tokens, creating more focused responses. Higher values allow consideration of diverse vocabulary choices. According to the repository's guidance, these parameters should be adjusted based on your prompt's complexity and the desired output characteristics.

Standard Prompt Formats and Few-Shot Learning

The repository establishes a canonical QA style as a foundational pattern for structuring interactions. This format uses clear delimiters such as Q: <question>? A: to signal the expected input-output relationship to the model.

The Power of In-Context Examples

Few-shot prompting extends the standard format by providing multiple (question, answer) pairs before the target query. This technique enables in-context learning, where the model extracts task patterns from examples rather than relying solely on pre-trained knowledge. As implemented in guides/prompts-intro.md, few-shot examples are particularly effective for classification tasks, format transformations, and style matching where explicit instructions alone prove insufficient.

The Four Core Elements of a Prompt

The repository defines a modular framework for prompt construction consisting of four optional components that can be mixed and matched depending on the problem domain:

  • Instruction: The explicit task directive telling the model what operation to perform (e.g., "Translate the following text to French").
  • Context: External information or background knowledge that guides the model's understanding of the task scope.
  • Input Data: The specific content or query requiring processing, often separated from instructions using delimiters like ###.
  • Output Indicator: Signals that specify the desired response format, such as requesting JSON, bullet points, or specific data structures.

These elements work synergistically in guides/prompts-intro.md to create robust prompts that minimize ambiguity and maximize reproducibility across different LLM providers.

General Design Tips for Effective Prompts

The repository provides specific guidelines for prompt optimization based on empirical testing. Start simple and iteratively add complexity only when baseline performance proves inadequate. Place the instruction first, preferably separated from context by clear delimiters such as ### or triple quotes.

Be specific about desired output format and style rather than assuming the model will infer your preferences. Avoid vague negative instructions (e.g., "don't be verbose"); instead, state exactly what you want (e.g., "provide a one-sentence answer"). These principles, documented in the general tips section of guides/prompts-intro.md, help developers converge on effective prompts through systematic iteration rather than random trial and error.

Practical Implementation Examples

Below are three practical implementations demonstrating the basic concepts of prompt engineering using the OpenAI API. These patterns apply universally to any LLM provider.

Example 1: Raw Completion (Basic Prompt)

import openai

openai.api_key = "YOUR_API_KEY"

response = openai.Completion.create(
    model="text-davinci-003",
    prompt="The sky is",
    temperature=0.7,
    max_tokens=50,
)
print(response.choices[0].text.strip())

This demonstrates raw continuation without explicit instruction, showing why task framing matters.

Example 2: Few-Shot QA Format (Standard Prompt)

prompt = """
Q: What is the capital of France?
A: Paris

Q: Who wrote "Pride and Prejudice"?
A: Jane Austen

Q: Explain the concept of prompt engineering.
A:"""

response = openai.Completion.create(
    model="text-davinci-003",
    prompt=prompt,
    temperature=0.3,   # low temperature for factual answer

    max_tokens=100,
)
print(response.choices[0].text.strip())

This implementation demonstrates few-shot prompting with clear instruction, input, and output indicator elements.

Example 3: Structured Elements with Delimiters

prompt = """

### Instruction ###

Extract all place names from the following text and list them as a comma-separated string.

### Input ###

Although these developments are encouraging to researchers, much is still a mystery. "We often have a black box between the brain and the effect we see in the periphery," says Henrique Veiga-Fernandes, a neuroimmunologist at the Champalimaud Centre for the Unknown in Lisbon.

### Output ###

"""

response = openai.Completion.create(
    model="text-davinci-003",
    prompt=prompt,
    temperature=0.0,   # deterministic extraction

    max_tokens=60,
)
print(response.choices[0].text.strip())

This illustrates the four prompt elements (instruction, context, input, output indicator) to obtain structured, deterministic answers.

Summary

  • Explicit instructions transform raw LLM completion into reliable task execution.
  • Temperature and top_p control the randomness-focus spectrum, requiring calibration based on task requirements.
  • Few-shot examples enable in-context learning through the standard QA format documented in guides/prompts-intro.md.
  • Four modular elements (instruction, context, input, output indicator) provide a systematic framework for prompt construction.
  • Iterative simplicity—starting basic and adding complexity only when necessary—yields faster convergence than complex initial attempts.

Frequently Asked Questions

What is the difference between zero-shot and few-shot prompting?

Zero-shot prompting provides only instructions without examples, relying entirely on the model's pre-trained knowledge. Few-shot prompting includes several input-output examples before the actual query, allowing the model to infer patterns through in-context learning. According to the dair-ai repository, few-shot approaches significantly improve performance on classification and formatting tasks.

How does temperature affect LLM outputs in prompt engineering?

Temperature scales the probability distribution of token selection. Values approaching 0.0 make the model deterministic and focused, ideal for factual or code generation tasks. Values approaching 1.0 increase randomness and creativity, suitable for brainstorming or creative writing. The repository recommends pairing low temperature with explicit formatting instructions for extraction tasks.

What are the essential components of a well-structured prompt?

The repository identifies four optional but powerful components: the instruction (task directive), context (background information), input data (specific content to process), and output indicator (format specification). While not all elements are required for every task, explicit use of delimiters like ### to separate these components improves model comprehension and output consistency.

Where can I find the official documentation for basic prompt engineering concepts?

The primary documentation resides in guides/prompts-intro.md within the dair-ai/Prompt-Engineering-Guide repository. Supplementary patterns appear in guides/prompts-basic-usage.md and guides/prompts-advanced-usage.md. The README.md file provides navigation and learning paths for both beginners and advanced practitioners.

Have a question about this repo?

These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:

Share the following with your agent to get started:
curl -s "https://instagit.com/install.md"

Works with
Claude Codex Cursor VS Code OpenClaw Any MCP Client

Maintain an open-source project? Get it listed too →