Workflow-001: Prompt Engineering Pipeline
FreshSource: Building with the Claude API
Document Control
| Field | Value |
|---|---|
| Workflow ID | WF-001 |
| Version | 1.0 |
| Status | Active |
| Last Updated | 2024-12 |
Overview
A systematic approach to writing, testing, and evaluating prompts.
Workflow Diagram
Phase 1: Define Task
Questions to answer:
- What is the input format?
- What is the expected output format?
- What are the edge cases?
- What quality criteria matter?
- 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
| Element | Purpose |
|---|---|
| Role | Sets expertise and tone |
| Guidelines | Boundaries and rules |
| Format | Structure of response |
| Examples | Demonstrates 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
| Method | Description | Best For |
|---|---|---|
| Exact Match | Output equals expected string | Classification, extraction |
| Contains Check | Output contains required keywords | Open-ended responses |
| LLM-as-Judge | Another LLM scores the output | Quality, tone, completeness |
| Semantic Similarity | Embedding distance to expected | Paraphrasing, 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