Overview
Theprompt_snapshots table stores named snapshots of a specific prompt_version with variable values filled in. This allows users to save and reuse prompts with specific configurations (e.g., “Production API prompt” with production URL variables).
Schema
Primary key. Auto-generated using
gen_random_uuid().Owner of the snapshot. References
auth.users(id) with ON DELETE CASCADE.The specific version this snapshot is based on. References
prompt_versions(id) with ON DELETE CASCADE.Human-readable snapshot name (e.g., “Production Settings”, “Testing with Mock Data”).
Key-value pairs for variable substitution. Defaults to
'{}'::jsonb (empty object).Example:Creation timestamp. Defaults to
timezone('utc', now()).Last modification timestamp. Defaults to
timezone('utc', now()). Auto-updated by handle_updated_at() trigger.Indexes
- idx_prompt_snapshots_user_id: Fast lookup of all snapshots for a user
- idx_prompt_snapshots_prompt_version_id: Fast lookup of all snapshots for a specific version
Row Level Security
Relationships
- Many-to-One with
prompt_versions: Each snapshot references one specific version - Many-to-One with
auth.users: Each snapshot belongs to one user - Many-to-One (indirect) with
prompts: Viaprompt_version_id → prompt_versions.prompt_id
Cascade Behavior
- Delete User: Deletes all their snapshots
- Delete Prompt Version: Deletes all snapshots referencing that version
- Delete Prompt: Cascades to versions, then to snapshots
Variable Resolution
Snapshots work with PromptRepo’s resolution engine (see src/features/resolution-engine/). The engine:- Fetches the
contentfrom the referencedprompt_version - Parses placeholders like
{{variable_name}}using src/lib/utils/variable-parser.ts - Substitutes values from the
variablesJSONB field - Returns the resolved prompt ready for use
Example
Prompt Version Content:Common Queries
Get All Snapshots for a User
Get Snapshots for a Specific Version
Get Snapshot with Full Version Data
Create a Snapshot
Update Snapshot Variables
Triggers
Updated At
updated_at = now() on every UPDATE.
TypeScript Types
Use Cases
- Environment-Specific Prompts: Save “Development”, “Staging”, “Production” snapshots with different API endpoints
- A/B Testing: Create snapshots with different parameter values (temperature, model, max_tokens)
- Client Configurations: Store customer-specific variable sets for the same base prompt
- Quick Recall: Save frequently-used variable combinations for one-click access
MCP Server Integration
Snapshots are exposed via the Model Context Protocol (MCP) server at/api/mcp. The resolve_prompt tool can accept snapshot IDs to retrieve pre-configured variable sets. See CLAUDE.md for MCP server details.
Migration File
- 20260208000004_prompt_snapshots.sql: Table creation, indexes, triggers, and RLS policies