> ## Documentation Index
> Fetch the complete documentation index at: https://prompt.university/llms.txt
> Use this file to discover all available pages before exploring further.

# Lesson 1.2: Anatomy of a Prompt

> Master the components and structure of effective prompts

<Info>
  **Duration:** 45 minutes
</Info>

## Introduction

Not all prompts are created equal. Understanding the components of effective prompts is like learning the ingredients of a great recipe—once you know what goes where and why, you can create variations for any situation.

## Prompt Components

Every effective prompt can be broken down into four key elements:

<Steps>
  <Step title="Instruction">
    **What you want the LLM to do**

    Clear, actionable directive that specifies the task
  </Step>

  <Step title="Context">
    **Background information or constraints**

    Additional details that shape how the task should be performed
  </Step>

  <Step title="Input Data">
    **The specific content to process**

    The actual text, code, or information the model should work with
  </Step>

  <Step title="Output Indicator">
    **Hints about desired format**

    Signals about structure, length, or style of the response
  </Step>
</Steps>

<Note>
  Not every prompt needs all four components! Simple tasks might only need an instruction and input, while complex tasks benefit from all four.
</Note>

## Template Structures

### Single Variable Template

The simplest form—one placeholder for dynamic content:

```
Please give me some suggestions for {activity}.
```

**Example:**

```
Please give me some suggestions for a fun weekend.
```

### Multi-Variable Template

Multiple placeholders for different pieces of information:

```
Here is a sentence: {sentence1}
Here is another sentence: {sentence2}

Compute the semantic similarity between the two sentences.
```

**Example:**

```
Here is a sentence: The cat sat on the mat.
Here is another sentence: A feline rested on the rug.

Compute the semantic similarity between the two sentences.
```

### The "Name:Content" Format

A powerful organizational pattern for complex prompts:

```
Task: Translation
Source language: English
Target language: Chinese
Style: Formal text
Template: Translate the following sentence: {sentence}
```

**Why it works:**

* Clear structure reduces ambiguity
* Easy to modify individual components
* Helps LLMs parse different types of information

## Role Assignment

Assigning a role or persona can dramatically improve output quality:

### Basic Role Assignment

```
You are a computer scientist with extensive knowledge in deep learning.

Please explain the following concept to a 10-year-old child, 
using simple examples.

Concept: {concept}
```

### Role with Specific Expertise

```
You are a professional copywriter specializing in e-commerce 
product descriptions. You excel at highlighting benefits while 
maintaining authenticity.

Write a product description for: {product}
```

### Role with Behavioral Guidelines

```
You are a helpful customer service representative. You are:
- Patient and empathetic
- Clear and concise in explanations
- Focused on solving problems
- Professional but friendly

Customer inquiry: {inquiry}
```

<Tip>
  Role assignment works because it activates relevant patterns in the model's training data. When you say "You are a poet," you're essentially saying "generate text that matches patterns associated with poetry."
</Tip>

## Common Prompt Formats

### Q\&A Format

Simple and effective for factual queries:

```
Q: What causes seasons on Earth?
A:
```

### Conversation Continuation

For dialogue generation:

```
John: How was your day?
David: Pretty good, thanks for asking!
John: Did you finish that project?
David:
```

### Instruction-Following Format

Clear directive with context:

```
Instruction: Summarize the following article in 3 bullet points.

Article: {article_text}

Summary:
```

### Fill-in-the-Blank (Cloze)

Useful for classification and completion:

```
The sentiment of the review "This product exceeded my expectations!" 
is ___.

Options: positive, negative, neutral
```

## Formatting Techniques

### Using Delimiters

Delimiters clearly separate different parts of your prompt:

```
Translate the following text (delimited by triple quotes) to German.

Text: """I have an orange."""

Translation:
```

**Common delimiters:**

* Triple quotes: `"""`
* Triple backticks: ` ``` `
* XML-style tags: `<text>...</text>`
* Brackets: `[...]`

### Code-Style Formatting

Particularly effective for pattern-based tasks:

```
[English] = [I have an apple.]
[German] = [Ich habe einen Apfel.]
[English] = [I have an orange.]
[German] =
```

### Structured Lists

For multi-step or multi-part tasks:

```
Analyze the following text and provide:

1. Main topic
2. Key arguments (list 3)
3. Tone (formal/informal/neutral)
4. Target audience

Text: {text}
```

## Template Examples by Task Type

<Tabs>
  <Tab title="Classification">
    ```
    Task: Sentiment Classification
    Categories: Positive, Negative, Neutral

    Text: "{text}"

    Classification:
    ```
  </Tab>

  <Tab title="Extraction">
    ```
    Extract the following information from the text:
    - Person names
    - Organizations
    - Locations
    - Dates

    Text: "{text}"

    Extracted information:
    ```
  </Tab>

  <Tab title="Generation">
    ```
    Generate a {content_type} with these specifications:

    Topic: {topic}
    Tone: {tone}
    Length: {length}
    Target audience: {audience}

    {content_type}:
    ```
  </Tab>

  <Tab title="Transformation">
    ```
    Transform the following text:

    Source format: {source_format}
    Target format: {target_format}
    Preserve: {what_to_preserve}

    Input: "{input_text}"

    Output:
    ```
  </Tab>
</Tabs>

## Advanced Template Patterns

### Conditional Instructions

```
You are a writing assistant. Analyze the following text and:

IF the text is less than 100 words:
  - Expand it to at least 200 words
  - Add more descriptive details
  
IF the text is more than 500 words:
  - Summarize to under 300 words
  - Keep key points

Text: {text}
```

### Multi-Stage Templates

```
Stage 1: Read and understand the following code
Stage 2: Identify any bugs or issues
Stage 3: Suggest improvements
Stage 4: Provide corrected version

Code:
{code}

Analysis:
```

### Template with Examples

```
Task: Convert casual text to professional tone

Example 1:
Input: "Hey, can u send me that file?"
Output: "Could you please send me that file?"

Example 2:
Input: "Thx for ur help!"
Output: "Thank you for your assistance."

Now convert:
Input: "{casual_text}"
Output:
```

## Best Practices

<CardGroup cols={2}>
  <Card title="Be Explicit" icon="bullseye">
    Don't assume the model knows what you want—state it clearly
  </Card>

  <Card title="Use Structure" icon="table">
    Organized prompts are easier for models to parse correctly
  </Card>

  <Card title="Provide Context" icon="circle-info">
    Background information helps guide appropriate responses
  </Card>

  <Card title="Specify Format" icon="align-left">
    Tell the model how you want the output structured
  </Card>
</CardGroup>

## Common Pitfalls

<Warning>
  **Avoid these mistakes:**

  1. **Vague instructions:** "Tell me about climate change" vs. "Explain three main causes of climate change in 150 words"

  2. **Missing context:** Not specifying tone, audience, or purpose

  3. **Ambiguous formatting:** Unclear where input ends and instruction begins

  4. **Contradictory elements:** Asking for "brief but comprehensive" without clarifying priority
</Warning>

## Practice Exercise

Create prompt templates for these scenarios:

<AccordionGroup>
  <Accordion title="Exercise 1: Email Response Generator">
    **Requirements:**

    * Role: Professional assistant
    * Input: Original email
    * Context: Relationship (colleague/client/manager)
    * Output: Appropriate response

    <Accordion title="Sample Solution">
      ```
      You are a professional email assistant.

      Relationship: {relationship}
      Tone: {formal/friendly/neutral}

      Original email:
      """
      {original_email}
      """

      Write an appropriate response that:
      - Addresses all points raised
      - Maintains professional tone
      - Is concise (under 200 words)

      Response:
      ```
    </Accordion>
  </Accordion>

  <Accordion title="Exercise 2: Code Documentation Generator">
    **Requirements:**

    * Input: Code snippet
    * Output: Documentation with description, parameters, returns, examples

    <Accordion title="Sample Solution">
      ```
      You are a technical documentation specialist.

      Generate comprehensive documentation for the following code:

      Code:
      ```

      {code_snippet}

      ```

      Documentation should include:
      1. Brief description (1-2 sentences)
      2. Parameters (name, type, description)
      3. Return value (type, description)
      4. Usage example
      5. Edge cases or notes

      Documentation:
      ```
    </Accordion>
  </Accordion>

  <Accordion title="Exercise 3: Content Summarizer">
    **Requirements:**

    * Input: Long article
    * Context: Target audience and purpose
    * Output: Summary with key points

    <Accordion title="Sample Solution">
      ```
      Task: Article Summarization
      Target audience: {audience}
      Purpose: {purpose}
      Length: {word_count} words

      Article:
      """
      {article_text}
      """

      Create a summary that:
      - Captures main arguments
      - Highlights key data/facts
      - Maintains original tone
      - Is accessible to target audience

      Summary:
      ```
    </Accordion>
  </Accordion>
</AccordionGroup>

## Key Takeaways

<Steps>
  <Step title="Four Core Components">
    Instruction, Context, Input Data, Output Indicator—use as needed
  </Step>

  <Step title="Templates Enable Reuse">
    Create templates with variables for consistent, scalable prompting
  </Step>

  <Step title="Format Matters">
    Structure and delimiters help models parse your intent correctly
  </Step>

  <Step title="Role Assignment Works">
    Personas activate relevant patterns in the model's training
  </Step>
</Steps>

## Next Steps

You now understand how to structure effective prompts. Next, you'll learn how to teach models new tasks through examples—without any training!

<Card title="Continue to Lesson 1.3: In-Context Learning" icon="arrow-right" href="/module-1/lesson-3">
  Discover zero-shot, one-shot, and few-shot learning techniques
</Card>
