Claude Academy
Interactive

Prompt Engineering Lab

Build better prompts with the interactive builder, browse ready-to-use templates, and study before/after transformations that show what makes a great prompt.

Prompt Builder

Great prompts follow a layered structure. The 6-layer framework helps you write prompts that get consistent, high-quality results from Claude every time.

1
Role
Who Claude should be
2
Context
Background information
3
Task
What to accomplish
4
Constraints
Rules and limits
5
Format
Output structure
6
Examples
Show, don't tell

Build Your Prompt

Who should the AI act as? (e.g., 'You are an expert Python developer')

What background information does the AI need?

What specific task should the AI perform?

What rules or limitations should the AI follow?

How should the output be structured?

Provide example input/output pairs to guide the AI.

Live Preview

Start typing to see your prompt preview...

Template Library

Ready-to-use prompt templates. Click any template to copy it, then customize the bracketed placeholders for your use case.

Debug This Error

Debugging

Identify root cause, explain why it happens, and provide the fix.

Code Review

Coding

Review code for security, performance, style, and edge cases.

Write Tests

Coding

Write comprehensive tests covering happy path, edge cases, and errors.

Explain This Code

Coding

Break down complex code with line-by-line explanation.

Refactor for Readability

Coding

Improve code structure while maintaining functionality.

Design a REST API

Coding

Design RESTful API endpoints with request/response schemas.

Write a Blog Post

Writing

Structured blog post with hook, sections, and actionable conclusion.

Write Technical Documentation

Writing

Clear technical docs with examples, parameters, and edge cases.

Draft a Professional Email

Writing

Craft a clear, professional email with the right tone.

Write Commit Messages

Writing

Generate conventional commit messages from a diff.

Analyze This Data

Analysis

Extract insights, patterns, and actionable recommendations from data.

Compare Technical Options

Analysis

Side-by-side comparison of technical choices with recommendation.

Architecture Review

Analysis

Evaluate system architecture for scalability and reliability.

Root Cause Analysis

Debugging

Systematic investigation to find the real source of a bug.

Performance Debugging

Debugging

Identify and fix performance bottlenecks in code.

Fix This Regex

Debugging

Debug and explain regex patterns with test cases.

Claude Code Task Prompt

Claude Code

Structure a complex task for Claude Code to execute.

Write a CLAUDE.md

Claude Code

Generate a project-specific CLAUDE.md for Claude Code.

PR Review Assistant

Claude Code

Use Claude Code to review a pull request thoroughly.

Create Migration Guide

Claude Code

Plan and execute a codebase migration step by step.

Security Audit

Analysis

Scan code for common security vulnerabilities.

Convert Between Languages

Coding

Translate code from one language to another idiomatically.

Before / After Gallery

See how vague prompts become powerful ones. Each pair shows the transformation with an explanation of what makes the improved version work.

Fixing Code
Before
fix my code
After
Debug this Python function that should return the sum of even numbers in a list but returns 0 for [2, 4, 6]. Here's the code:

def sum_evens(nums):
    total = 0
    for n in nums:
        if n % 2 == 0:
            total += n
        return total

The good prompt specifies the language, the expected vs actual behavior, provides a concrete failing input, and includes the code. Claude can immediately identify that the return is inside the loop.

Writing Content
Before
write a blog post
After
Write a 1200-word blog post about React Server Components for mid-level frontend developers. Tone: conversational but technical. Structure: intro hook with a pain point, 3 sections with descriptive subheadings, 2 code examples showing before/after, actionable conclusion with next steps.

The good prompt defines topic, audience, length, tone, structure, and concrete deliverables. This eliminates multiple rounds of revision.

Getting Explanations
Before
explain kubernetes
After
Explain Kubernetes to a backend developer who uses Docker but hasn't worked with orchestration. Cover: what problems it solves, core concepts (pods, services, deployments), and a minimal example of deploying a Node.js app. Skip the history and comparison with Docker Swarm.

The good prompt establishes the reader's existing knowledge, scopes what to cover AND what to skip, and asks for a practical example. This avoids a generic Wikipedia-style answer.

Writing Tests
Before
write tests for my function
After
Write Jest tests for this TypeScript function that validates email addresses. Cover: valid emails (user@domain.com), edge cases (plus addressing, subdomains), and invalid inputs (missing @, spaces, empty string). Use describe/it blocks with clear test names.

export function isValidEmail(email: string): boolean { ... }

The good prompt specifies the testing framework, language, types of test cases, and preferred test structure. It also provides the function signature for context.

Code Review
Before
review this code
After
Review this Express.js authentication middleware for: 1) Security vulnerabilities (especially JWT handling) 2) Error cases that return 500 instead of proper status codes 3) Race conditions with the database call. The code handles ~10K requests/minute in production.

The good prompt focuses the review on specific concerns, mentions the technology stack, and provides production context (scale) that affects the recommendations.

Database Queries
Before
write me a SQL query
After
Write a PostgreSQL query to find the top 10 customers by total order value in the last 30 days. Tables: customers (id, name, email), orders (id, customer_id, total, created_at). Include customers with no orders as $0. Format the output as: name, email, total_spent (descending).

The good prompt specifies the database, the exact result needed, provides the schema, handles the edge case (no orders), and defines the output format and sort order.

Refactoring
Before
make this code better
After
Refactor this React component to: 1) Extract the fetch logic into a custom hook 2) Replace the nested ternaries with early returns 3) Add proper TypeScript types (currently using 'any' in 4 places) 4) Memoize the expensive filter operation. Keep the component's behavior identical.

The good prompt lists specific refactoring targets, explains what to preserve, and calls out exact issues. 'Make it better' could mean anything; this is actionable.

DevOps Tasks
Before
help me deploy my app
After
Create a GitHub Actions workflow to deploy a Next.js 14 app to AWS EC2. Requirements: run on push to main, build with Node 20, run tests first, SSH deploy to ec2-user@my-server, use PM2 for process management, send Slack notification on success/failure. Our secrets are in GitHub Secrets.

The good prompt specifies the CI/CD platform, framework, infrastructure, Node version, deployment method, process manager, and notification requirements. Every choice is made explicit.

Writing Regex
Before
write a regex for phone numbers
After
Write a JavaScript regex to validate US phone numbers. Must accept: (123) 456-7890, 123-456-7890, 123.456.7890, 1234567890, +1 123 456 7890. Must reject: 123-45-6789 (too few digits), letters, numbers with country codes other than +1. Return named capture groups for area code, prefix, and line number.

The good prompt lists exact formats to match and reject, specifies the language (JS regex flavor matters), and asks for capture groups. This eliminates guesswork about edge cases.