🔥 0
0
Lesson 2 of 10 20 min +150 XP

Prompt Structure Fundamentals

The Anatomy of a Great Prompt

When working with LLMs via the API, you typically want to send one comprehensive message and get an accurate response on the first try. This requires a well-organized prompt structure.

The 10-Point Prompt Framework

Anthropic recommends this structure for building production-quality prompts:

1. Task Context       - What is the model here to do?
2. Tone Context       - How should the model respond?
3. Background Data    - Static information it needs
4. Dynamic Content    - The actual input to process
5. Detailed Instructions - Step-by-step guidance
6. Examples           - Demonstrations of expected behavior
7. Output Format      - How to structure the response
8. Task Reminder      - Reinforce key requirements
9. Important Guidelines - Critical constraints
10. Prefill           - Start the response

Framework Visualization

┌─────────────────────────────────────────────────────────┐
│                     SYSTEM PROMPT                        │
├─────────────────────────────────────────────────────────┤
│  1. Task Context                                        │
│     "You are an AI assistant that..."                   │
├─────────────────────────────────────────────────────────┤
│  2. Tone Context                                        │
│     "Be factual, confident, avoid guessing..."          │
├─────────────────────────────────────────────────────────┤
│  3. Background Data                                     │
│     Static info: form structure, field meanings, etc.   │
└─────────────────────────────────────────────────────────┘

┌─────────────────────────────────────────────────────────┐
│                      USER PROMPT                         │
├─────────────────────────────────────────────────────────┤
│  4. Dynamic Content                                     │
│     The actual input (images, text, data)               │
├─────────────────────────────────────────────────────────┤
│  5. Detailed Instructions                               │
│     Step-by-step task breakdown                         │
├─────────────────────────────────────────────────────────┤
│  6. Examples (Few-Shot)                                 │
│     Input/output pairs demonstrating behavior           │
├─────────────────────────────────────────────────────────┤
│  7. Output Format                                       │
│     JSON, XML, specific structure                       │
├─────────────────────────────────────────────────────────┤
│  8. Task Reminder                                       │
│     "Remember to..."                                    │
├─────────────────────────────────────────────────────────┤
│  9. Important Guidelines                                │
│     Critical constraints and rules                      │
└─────────────────────────────────────────────────────────┘

┌─────────────────────────────────────────────────────────┐
│                   ASSISTANT PREFILL                      │
├─────────────────────────────────────────────────────────┤
│  10. Prefill                                            │
│      Start response: "{" or "<result>"                  │
└─────────────────────────────────────────────────────────┘

When to Use Each Element

ElementUse When...Skip When...
Task ContextAlwaysNever
Tone ContextSpecific voice neededDefault tone is fine
BackgroundStatic info existsInfo is in input
Dynamic ContentProcessing dataPure generation
InstructionsComplex taskSimple task
ExamplesPrecision criticalClear enough
Output FormatParsing neededFree-form OK
ReminderLong promptShort prompt
GuidelinesEdge cases existSimple task
PrefillJSON/XML outputFree text

Example: Simple vs. Structured Prompt

Simple (Unreliable)

Summarize this article.

Structured (Reliable)

Task: You are a content summarizer that creates concise summaries.

Tone: Be factual and neutral. Avoid editorializing.

<article>
{article_content}
</article>

Instructions:
1. Read the entire article
2. Identify the main thesis
3. Extract 3-5 key points
4. Write a 2-3 sentence summary

Output Format:
<summary>
<main_point>...</main_point>
<key_points>
  <point>...</point>
</key_points>
<summary_text>...</summary_text>
</summary>

Remember: Only include facts from the article. Do not add external information.

System Prompt vs User Prompt

System Prompt (via API):
  • Persistent across conversation
  • Contains static context
  • Defines role and behavior
  • Great for caching
User Prompt:
  • Changes per request
  • Contains dynamic input
  • Includes specific task details

Order Matters

Research shows that information placement affects results:

  • Put critical info at start and end - The "primacy" and "recency" effects
  • Group related information - Easier to reference
  • Progressive disclosure - Context before details

Key Takeaways

  • Structure matters - Organized prompts produce better results
  • Use the 10-point framework - As a checklist, not a requirement
  • Separate system and user prompts - Static vs. dynamic content
  • Order information strategically - Important info at start and end
  • Not all elements needed - Use what's relevant to your task

Next Lesson

Next, we'll explore Task and Tone Context - the first two critical elements that set the stage for everything else.