HomePrompt EngineeringPrompt Templates & Patterns
intermediate16 min read· Module 7, Lesson 2

📋Prompt Templates & Patterns

Copy-paste ready templates for summarization, extraction, classification, and more

Prompt Templates & Patterns

Instead of writing prompts from scratch every time, use proven, effective templates. In this lesson, you'll find ready-to-use templates you can copy and adapt.

1. Summarization Template

Summarize the following text in [number] key points. Rules: - Each point should be a single clear sentence - Focus on the most important information - Ignore secondary details Text: """ [paste text here] """

Code example:

JavaScript
async function summarize(text, numPoints = 5) { const response = await client.messages.create({ model: "claude-sonnet-4-20250514", max_tokens: 1024, messages: [{ role: "user", content: `Summarize the following text in ${numPoints} key points.\n\n"""${text}"""` }], }); return response.content[0].text; }

2. Data Extraction Template

Extract the following from the text and return as JSON: - name - email - phone - company If a field is not found, use null. Return valid JSON only, no additional text. Text: """ [paste text here] """

Code example:

JavaScript
async function extractInfo(text, fields) { const response = await client.messages.create({ model: "claude-sonnet-4-20250514", max_tokens: 1024, messages: [{ role: "user", content: `Extract ${fields.join(", ")} from the text as JSON. Use null for missing fields.\n\n"""${text}"""` }], }); return JSON.parse(response.content[0].text); }

3. Classification with Few-Shot

JavaScript
async function classifySentiment(text) { const response = await client.messages.create({ model: "claude-haiku-3-5-20241022", max_tokens: 50, messages: [{ role: "user", content: `Classify sentiment as: positive, negative, or neutral Examples: "Great product, highly recommend!" — positive "Terrible, would never buy again" — negative "It's okay, nothing special" — neutral Now classify: "${text}" —` }], }); return response.content[0].text.trim(); }

4. Code Review Template

Review the following code for: 1. Logic errors 2. Security issues 3. Performance problems 4. Readability For each issue: severity, line number, description, suggested fix with code.

5. Translation Template

Translate from [source language] to [target language]. Rules: - Maintain the same tone and style - Do not translate proper nouns or technical terms - Preserve formatting

6. Document Q&A Template

You answer questions based ONLY on the provided document. Rules: - Answer only from the document - If not found, say "This information is not in the document" - Quote relevant sections when answering

7. Reusable Template Library

JavaScript
const templates = { summarize: (text, n) => `Summarize in ${n} points:\n"""${text}"""`, classify: (text, categories) => `Classify into: ${categories.join(", ")}. Reply with just the label.\n\n"${text}"`, extract: (text, fields) => `Extract ${fields.join(", ")} as JSON. Use null for missing.\n\n"""${text}"""`, translate: (text, from, to) => `Translate from ${from} to ${to}. Keep proper nouns and code.\n\n"""${text}"""`, }; // Usage const prompt = templates.classify( "The product broke after one day", ["positive", "negative", "neutral"] );

8. Step-by-Step Explanation Template

Explain [topic] step by step. Rules: - Assume the reader has no background - Use simple language - Include an analogy or real-world example - End with a summary

Tips for Effective Templates

  1. Be specific — Define exactly what you want and don't want
  2. Give examples — Examples are more powerful than instructions
  3. Specify format — Say how you want output (JSON, bullets, table...)
  4. Use delimiters — Separate instructions from data with """ or ---
  5. Test and iterate — Try the template with different data and refine

Summary

Ready-made templates save time and improve result quality. Save your favorite templates and use them as starting points for every new task.

Next: We'll learn how to build AI agent loops.