Home/
Part XIV — Team Workflows and "Shipping With Adults in the Room"/43. Collaboration Patterns/43.2 Shared prompt libraries and templates
43.2 Shared prompt libraries and templates
Overview and links for this section of the guide.
On this page
The Problem
Without a shared library, every developer reinvents common prompts:
- 5 devs = 5 different SQL generation prompts
- No consistency in error handling
- Best practices aren't shared
- Bugs fixed in one prompt aren't fixed in copies
Library Structure
prompts/
├── core/
│ ├── safety-rules.md # Included in ALL prompts
│ ├── output-formats.md # JSON, markdown templates
│ └── error-handling.md # Standard error responses
├── domains/
│ ├── sql-generation.md # SQL from natural language
│ ├── code-review.md # Review code changes
│ ├── summarization.md # Document summarization
│ └── classification.md # Text classification
├── components/
│ ├── chain-of-thought.md # Reasoning blocks
│ ├── few-shot-header.md # Example injection
│ └── self-check.md # Self-verification
└── config/
├── models.yaml # Model configs per use case
└── eval-sets/ # Test data per prompt
Template System
// prompt-template.ts
export function buildPrompt(templateName: string, variables: Record): string {
const template = loadTemplate(templateName);
const coreRules = loadTemplate('core/safety-rules');
let prompt = `${coreRules}\n\n${template}`;
// Variable substitution
for (const [key, value] of Object.entries(variables)) {
prompt = prompt.replace(new RegExp(`{{${key}}}`, 'g'), String(value));
}
return prompt;
}
// prompts/domains/sql-generation.md
`{{core/safety-rules}}
You generate SQL queries from natural language.
## Database Schema
{{schema}}
## Rules
- Only SELECT queries (no INSERT, UPDATE, DELETE)
- Use table aliases for clarity
- Always include LIMIT unless aggregating
## User Question
{{question}}
## Output
Return valid SQL only, no explanation.`
Usage
// Using the library
import { buildPrompt } from '@company/prompt-library';
const prompt = buildPrompt('domains/sql-generation', {
schema: databaseSchema,
question: userQuery
});
const response = await model.generateContent(prompt);
// Benefits:
// ✅ Safety rules automatically included
// ✅ Consistent format across team
// ✅ One place to update when improving
// ✅ Easy to test with standard eval set