Overview
Variables make prompts reusable by allowing you to define placeholders that get filled in at runtime. PromptRepo uses a simple{{variable}} syntax and includes a resolution engine for testing and deploying prompts with different values.
Variable Syntax
Basic Format
Variables use double curly braces:role, task, action, and content.
Syntax Rules
- Pattern:
{{variable_name}} - Names: Can contain letters, numbers, underscores, spaces, and special characters
- Whitespace: Spaces inside braces are trimmed (
{{ name }}becomesname) - Case-sensitive:
{{User}}and{{user}}are different variables - Multiline: Variables can appear across multiple lines
Variable Parser
Extracting Variables
The variable parser scans prompt content and extracts unique variable names:src/lib/utils/variable-parser.ts:13-31:
The regex uses non-greedy matching (
[^}]+?) to avoid capturing content beyond the closing braces.Resolving Variables
Replace variables with actual values:src/lib/utils/variable-parser.ts:49-73:
If a variable is not provided in the values object, the original placeholder remains unchanged (e.g.,
{{missing}} stays as {{missing}}).Resolution Engine
User Workflow
The resolution engine provides an interactive form for testing prompts:- View a prompt with variables
- Fill in the resolution form with test values
- See the resolved output in real-time
- Save successful configurations as snapshots
- Load snapshots to re-test or iterate
Hydration
When loading a snapshot, the resolution form is hydrated with saved variable values:src/features/resolution-engine/utils/hydration.ts:8-19:
Snapshots
What Are Snapshots?
Snapshots are saved configurations of variable values tied to a specific prompt version. They allow you to:- Save working test cases
- Document example use cases
- Share configurations with team members
- Quickly reproduce specific scenarios
Snapshot Schema
Creating Snapshots
Save the current resolution state:src/lib/validation/snapshot.ts:
- name: Required, 1-100 characters
- prompt_version_id: Must be a valid UUID
- variables: Must be a valid object (stored as JSONB)
Database Schema
Fromsupabase/migrations/20260208000004_prompt_snapshots.sql:1-10:
Snapshots reference
prompt_version_id, not prompt_id. This ensures snapshots remain tied to the exact prompt content they were created with, even if the prompt is later updated.Loading Snapshots
Fetch snapshots for a specific prompt version:variables field is stored as JSONB in PostgreSQL, so it’s automatically parsed into a JavaScript object.
MCP Integration
Resolving via API
The MCP API includes aresolve_prompt tool that fetches a prompt and resolves its variables:
src/features/mcp/tools/resolve-prompt.ts.
AI Agent Usage
AI agents (like Claude Desktop) can use the MCP API to:- List available prompts
- Get prompt details and see required variables
- Resolve prompts with context-specific values
- Use resolved prompts in their workflows
Best Practices
Descriptive Variable Names
Use clear names like
{{customer_name}} instead of {{x}}. This makes prompts self-documenting.Default Values
Document expected values in the prompt description or version notes. Variable resolution doesn’t support defaults.
Snapshot Naming
Give snapshots descriptive names that explain the use case: “Production config”, “Debug mode”, “Customer support tone”.
Version Stability
Snapshots are tied to specific versions. If you significantly change variables in a new version, previous snapshots may not apply cleanly.
Examples
Email Template
subject, recipient_name, greeting, topic, main_content, closing, sender_name
Code Review Prompt
language, focus_area_1, focus_area_2, focus_area_3, code
Multi-step Analysis
data_type, step_1, step_2, step_3, data, format
Limitations
Next Steps
Search
Find prompts by variable names in content
Collections
Organize related prompt templates
MCP Server
Use variable resolution in AI workflows
API Reference
API documentation for resolve_prompt