Claude With The Anthropic Api
← All lessons
Lesson 14Claude With The Anthropic Api

Structured data exercise

Summary audio

No audio recap for this lesson.

Study notes

Problem

  • Generate three AWS CLI commands in a single response with no additional commentary or explanation
  • Use only message prefilling and stop sequences (no prompt modification)

Solution Approach

Step 1: Initial Prefilling

  • Add an assistant message prefilled with three backticks (`) to skip initial commentary
  • Add a stop sequence of three backticks to end output at the right place
  • Result: Gets three commands but includes unwanted "bash" language identifier

Step 2: Refine Prefilling

  • Include "bash" in the prefilled message (`bash) to explicitly indicate markdown code block
  • This tells Claude it's writing bash-formatted commands
  • Prevents Claude from auto-adding the language identifier

Step 3: Advanced Prefilling

  • Use message prefilling to guide Claude's behavior beyond just syntax markers
  • Add descriptive text like "here are all three commands in a single block without any comments:" before the code block
  • This dramatically improves reliability and prevents unwanted bash comments

Key Insights

  • Message prefilling is not limited to special characters—you can include full instructional text
  • Prefilling helps Claude understand the desired format and reduces unwanted additions
  • Stop sequences work best when combined with strategic prefilling
  • Explicit formatting guidance in prefilled messages produces more consistent results

Takeaways

  • Message prefilling can include full instructional text, not just syntax markers, to guide Claude's behavior and format
  • Combining prefilling with stop sequences effectively controls output boundaries and prevents unwanted additions
  • Explicitly indicating the code block format (`bash) in the prefilled message prevents Claude from auto-adding language identifiers
  • Strategic prefilling that describes the desired output (e. g. , "here are all three commands in a single block without any comments") dramatically improves reliability
Flashcards 7 cards
Question
click to reveal · ←/→
Answer
click to flip back
Export to Anki (.tsv) ↓
Knowledge check 1 questions