Back to guides
6
5 min

Prompt Library

Reusable Prompts & Iteration

From Ad-Hoc to Systematic

So far you've written prompts one at a time. In production, you need a prompt library — a curated, tested, versioned collection of prompts your team reuses. This is the difference between "I asked ChatGPT" and "we have a reliable AI pipeline."

What Goes in a Prompt Library

A prompt library entry has five parts:

interface PromptEntry {
  id: string;            // "email-triage-v3"
  name: string;          // "Email Triage Classifier"
  version: number;       // 3
  systemPrompt: string;  // The system message
  userTemplate: string;  // Template with {{placeholders}}
  outputSchema: object;  // Expected JSON schema
  testCases: TestCase[]; // Inputs + expected outputs
}

1. Email Drafting Prompts

# email-reply-professional

System: You are a professional email assistant. Write clear, concise replies that match the tone of the original email. Keep replies under 150 words.

Template:
Original email:
{{original_email}}

Key points to address:
{{key_points}}

Tone: {{tone}}

Write a professional reply.

2. Data Extraction Prompts

# invoice-extractor-v2

System: You are a data extraction specialist. Return valid JSON only. No explanatory text.

Template:
Extract invoice data from this document. Return JSON matching:
{"invoice_id": string, "vendor": string, "amount": number, "date": string, "line_items": [...]}

Document:
{{document_text}}

3. Summarization Prompts

# meeting-summary

System: You summarize meeting transcripts into structured action items. Focus on decisions made, tasks assigned, and open questions.

Template:
Summarize this meeting transcript:
{{transcript}}

Output format:
## Decisions
## Action Items (with owner and deadline)
## Open Questions
## Next Meeting Topics

4. Analysis Prompts

# review-sentiment-analysis

System: You analyze customer reviews for product teams. Be specific about what customers like and dislike. Back every claim with a direct quote.

Template:
Analyze these {{count}} customer reviews for "{{product_name}}":
{{reviews}}

Return:
1. Overall sentiment (positive/mixed/negative)
2. Top 3 praised features (with quotes)
3. Top 3 complaints (with quotes)
4. Suggested improvements (based on complaint patterns)

Testing Prompts with Edge Cases

Every prompt in your library should have test cases:

{
  "test_cases": [
    {
      "name": "standard_email",
      "input": {"original_email": "Hi, can we schedule a call?", "key_points": ["Available Tuesday"], "tone": "friendly"},
      "expected_contains": ["Tuesday"],
      "expected_not_contains": ["Dear Sir/Madam"]
    },
    {
      "name": "empty_input",
      "input": {"original_email": "", "key_points": [], "tone": "professional"},
      "expected_behavior": "should ask for clarification, not hallucinate"
    },
    {
      "name": "hostile_email",
      "input": {"original_email": "Your product is garbage and I want a refund NOW", "key_points": ["Apologize", "Offer refund"], "tone": "empathetic"},
      "expected_contains": ["understand", "refund"],
      "expected_not_contains": ["garbage"]
    }
  ]
}

Test for: normal cases, empty inputs, adversarial inputs, very long inputs, non-English text, and inputs with special characters.

Versioning and Iteration

Prompts evolve. Track changes like code:

VersionChangeReasonTest Results
v1Initial prompt78% accuracy on test set
v2Added few-shot examplesMisclassifying edge cases89% accuracy
v3Added "if ambiguous" ruleNull handling was inconsistent94% accuracy

Never overwrite a working prompt. Create a new version so you can roll back.

Building Your Library

In this module, you'll build a prompt library with at least 4 entries:

  • Email drafter — professional replies using data/emails.json as test data
  • Data extractor — structured extraction from data/invoices.csv and data/products.json
  • Summarizer — meeting summaries from data/transcripts.json
  • Analyzer — review analysis from data/reviews.json
  • Each entry should have: system prompt, user template with placeholders, output schema, and at least 2 test cases.

    Store your library in the prompts/ directory. Use one file per prompt, with the test cases alongside.

    Key Takeaways

  • A prompt library turns ad-hoc AI usage into a reliable, repeatable system.
  • Every prompt entry needs: system prompt, user template, output schema, and test cases.
  • Test with edge cases — empty inputs, adversarial text, long documents, and special characters.
  • Version your prompts and track accuracy improvements across versions.
  • Your library is a living document. Iterate based on real usage patterns and failure modes.
  • This is chapter 6 of Prompt Engineering Essentials.

    Get the full hands-on course — free during early access. Build the complete system. Your projects become your portfolio.

    View course details