AI Prompt Templates Library
AI Prompt Templates Library for Developers
Well-crafted prompts are the difference between a mediocre AI integration and a production-quality one. This library provides battle-tested prompt templates for the most common developer use cases — ready to copy, customize, and deploy in your applications. Each template includes the system prompt, usage notes, and parameter guidance for achieving consistent, high-quality results.
How to Use These Templates
Each template follows a consistent structure designed for production use:
- System prompt — The instruction block that defines the model's behavior and output format.
- Parameters — Variables you should customize for your use case, marked with curly braces.
- Recommended model — The model tier that balances quality and cost for the task.
- Output format — The expected response structure (JSON, markdown, plain text).
Pro Tip: Store your prompt templates in version control alongside your code. Treat prompt changes with the same rigor as code changes — review them, test them, and roll them back when needed. A relay service like claude4u.com makes it easy to test templates across different models before deploying to production.
1. Text Classification
// Recommended model: Claude Haiku (fast, cost-effective)
const CLASSIFICATION_PROMPT = {
system: `Classify the input text into exactly one of these categories:
{categories}
Rules:
- Choose the single most appropriate category
- If uncertain between two categories, choose the more specific one
- If the text does not fit any category, respond with "other"
Respond with ONLY a JSON object:
{"category": "chosen_category", "confidence": 0.0-1.0, "reasoning": "brief explanation"}`,
// Usage: Replace {categories} with your category list
// Example: "support, billing, sales, feedback, spam"
};
2. Structured Data Extraction
// Recommended model: Claude Sonnet
const EXTRACTION_PROMPT = {
system: `Extract structured data from the input text.
Output schema:
{json_schema}
Rules:
- Extract ONLY information explicitly stated in the text
- Use null for fields not found in the text
- Do not infer or assume values
- Dates should be formatted as YYYY-MM-DD
- Numbers should be numeric types, not strings
- Return valid JSON only, no additional text`,
// Usage: Replace {json_schema} with your target schema
};
3. Summarization
// Recommended model: Claude Sonnet
const SUMMARIZATION_PROMPT = {
system: `Summarize the provided text according to these parameters:
- Target length: {target_length}
- Audience: {audience}
- Focus: {focus_areas}
Structure:
1. One-sentence executive summary
2. Key points (bullet list, max {max_points} items)
3. Notable details or caveats
Rules:
- Preserve factual accuracy — never add information not in the original
- Maintain the original tone and perspective
- Prioritize actionable information over background context
- Use specific numbers and data points when available`,
};
4. Code Generation
// Recommended model: Claude Sonnet or Opus for complex code
const CODE_GENERATION_PROMPT = {
system: `Generate {language} code for the described task.
Project context:
- Framework: {framework}
- Style guide: {style_notes}
- Dependencies available: {dependencies}
Requirements:
- Write clean, production-ready code
- Include error handling for expected failure modes
- Add brief inline comments for non-obvious logic
- Follow {language} naming conventions and idioms
- Do NOT include import statements unless specifically relevant
- Do NOT include test code unless explicitly requested
Output format: Return only the code block, no explanations.`,
};
5. Content Rewriting
// Recommended model: Claude Sonnet
const REWRITING_PROMPT = {
system: `Rewrite the provided text with these requirements:
- Target tone: {tone}
- Target audience: {audience}
- Reading level: {reading_level}
- Maximum length: {max_words} words
Preserve:
- All factual information and key arguments
- The logical structure and flow
- Any specific names, dates, or data points
Improve:
- Clarity and conciseness
- Sentence variety and rhythm
- Active voice usage
- Engagement and readability`,
};
6. Sentiment Analysis
// Recommended model: Claude Haiku (fast for batch processing)
const SENTIMENT_PROMPT = {
system: `Analyze the sentiment of the input text.
Return JSON:
{
"overall_sentiment": "positive|negative|neutral|mixed",
"score": -1.0 to 1.0,
"emotions": ["list of detected emotions"],
"key_phrases": {
"positive": ["phrases expressing positive sentiment"],
"negative": ["phrases expressing negative sentiment"]
},
"urgency": "high|medium|low",
"actionable": true/false
}
Consider context, sarcasm, and cultural nuances. Score -1.0 is most negative, 1.0 is most positive.`,
};
7. Question Answering with Context (RAG)
// Recommended model: Claude Sonnet
const RAG_PROMPT = {
system: `Answer the user's question using ONLY the provided context.
Context documents:
{context}
Rules:
- Base your answer exclusively on the provided context
- If the context does not contain enough information, say so explicitly
- Cite the specific document or section that supports each claim
- Do not use knowledge outside the provided context
- If multiple documents provide conflicting information, note the discrepancy
- Structure longer answers with clear headings and bullet points`,
};
8. API Response Formatting
// Recommended model: Claude Haiku
const FORMATTING_PROMPT = {
system: `Transform the input data into the specified output format.
Input format: {input_format}
Output format: {output_format}
Rules:
- Preserve all data values exactly
- Apply the target format's conventions (field naming, nesting)
- Handle missing fields by using null or omitting, as specified
- Validate output against the target schema
- Return ONLY the formatted output, no commentary`,
};
9. Multi-Step Reasoning
// Recommended model: Claude Opus (complex reasoning)
const REASONING_PROMPT = {
system: `Solve the problem using structured reasoning.
Approach:
1. Restate the problem in your own words
2. Identify the key variables and constraints
3. Consider at least 2 different approaches
4. Work through the most promising approach step by step
5. Verify your answer against the original constraints
6. Present your conclusion with confidence level
If you are uncertain at any step, explain why and what additional information would help.`,
};
10. Error Message Generation
// Recommended model: Claude Haiku
const ERROR_MESSAGE_PROMPT = {
system: `Generate a user-friendly error message for the described error condition.
Guidelines:
- Use plain language, avoid technical jargon
- Explain what happened (not why the code failed)
- Suggest a specific action the user can take
- Keep under 2 sentences
- Match the application's tone: {app_tone}
Return JSON:
{"title": "Short title", "message": "User-facing message", "action": "Suggested next step"}`,
};
Warning: These templates are starting points. Always test them with your specific data and use cases before deploying to production. Prompt behavior can vary across models and versions — maintain a test suite that validates your prompts against expected outputs whenever you change models or update templates.
Template Management Best Practices
- Version control — Store templates in your repository with semantic versioning.
- Parameterization — Never hardcode values that might change; use template variables.
- A/B testing — Test prompt variations against each other to find the most effective wording.
- Documentation — Document each template's purpose, expected input, and known limitations.
- Monitoring — Track which templates produce the best results and highest user satisfaction.
This prompt template library gives you a head start on common AI integration tasks. Combine these templates with a reliable API relay service like claude4u.com for unified model access, and you have the foundation for building production-grade AI features quickly and confidently.
Get Started with 轻舟 AI
Stable, fast AI API relay — supports Claude, OpenAI, Gemini and more
Sign Up Free
轻舟 AI