Skip to content

Workflow-001: Prompt Engineering Pipeline

Fresh

Source: Building with the Claude API

Document Control

FieldValue
Workflow IDWF-001
Version1.0
StatusActive
Last Updated2024-12

Overview

A systematic approach to writing, testing, and evaluating prompts.

Workflow Diagram

Phase 1: Define Task

Questions to answer:

  1. What is the input format?
  2. What is the expected output format?
  3. What are the edge cases?
  4. What quality criteria matter?
  5. What should definitely NOT happen?

Phase 2: Draft Prompt

Prompt Structure

python
system_prompt = """
You are a [ROLE] that [PRIMARY FUNCTION].

## Guidelines
- [RULE 1]
- [RULE 2]
- [RULE 3]

## Output Format
[EXPECTED FORMAT]

## Examples
[INCLUDE 2-3 EXAMPLES]
"""

Key Elements

ElementPurpose
RoleSets expertise and tone
GuidelinesBoundaries and rules
FormatStructure of response
ExamplesDemonstrates expectations

Phase 3: Create Test Cases

python
test_cases = [
    {
        "input": "Normal case input",
        "expected_output_contains": ["keyword1", "keyword2"],
        "expected_output_not_contains": ["bad_word"]
    },
    {
        "input": "Edge case input",
        "expected_output_contains": ["handled_correctly"]
    },
    {
        "input": "Adversarial input",
        "should_refuse": True
    }
]

Phase 4: Run Tests

python
import anthropic

def run_test(prompt, test_case):
    client = anthropic.Anthropic()

    response = client.messages.create(
        model="claude-sonnet-4-20250514",
        max_tokens=1024,
        system=prompt,
        messages=[{"role": "user", "content": test_case["input"]}]
    )

    output = response.content[0].text
    return evaluate_output(output, test_case)

Phase 5: Score Results

MethodDescriptionBest For
Exact MatchOutput equals expected stringClassification, extraction
Contains CheckOutput contains required keywordsOpen-ended responses
LLM-as-JudgeAnother LLM scores the outputQuality, tone, completeness
Semantic SimilarityEmbedding distance to expectedParaphrasing, summarization

Iteration Strategy

Verification Checklist

  • [ ] Task clearly defined with success criteria
  • [ ] Prompt includes role, guidelines, format
  • [ ] Test cases cover normal, edge, adversarial inputs
  • [ ] Automated test runner implemented
  • [ ] Score ≥80% achieved
  • [ ] Prompt documented and versioned

See Also

Based on Anthropic Academy courses