Prompts
Create and manage reusable prompt templates
Prompt management features are currently restricted to:
- Self-deployed instances
- Enterprise tier cloud accounts
Contact our sales team for Enterprise pricing and features.
R2R provides a powerful prompt management system that enables you to create, store, and reuse prompt templates across your application. The system supports variable substitution, input validation, and efficient caching for high-performance applications.
Refer to the prompts API and SDK reference for detailed examples for interacting with prompts.
Core Concepts
The prompt system operates using three main components:
- Templates - Reusable prompt patterns with variable placeholders
- Input Types - Type definitions for template variables ensuring proper usage
- Caching - Performance optimization for frequently used prompts
Template Management
Creating Templates
Templates are prompt patterns that can include variable placeholders. Each template includes:
- A unique name for identification
- The template text with variable placeholders
- Input type definitions specifying expected variable types
For example, a simple greeting template:
Input Validation
R2R automatically validates inputs against defined types before rendering templates. This ensures:
- Required variables are provided
- Values match their expected types
- Invalid or missing variables are caught early
Template Inheritance
Templates can build on each other through:
- Base templates for common patterns
- Specialized templates that extend base templates
- Override capabilities for customization
Using Prompts
Basic Usage
Templates can be used directly with input values:
System Prompts
Special system prompts can be defined for consistent AI interactions across your application. These provide:
- Base context for AI models
- Standard instruction sets
- Common constraints or rules
Task Prompts
Task-specific prompts build on system prompts to:
- Define specific operations or questions
- Include relevant context
- Guide model responses
Performance Optimization
The prompt system includes built-in performance features:
- Template Caching - Frequently used templates are cached in memory
- Render Caching - Common prompt/input combinations are cached
- Smart Invalidation - Cache updates when templates change
Conclusion
R2R’s prompt management system provides a robust foundation for working with AI models. Through templates, input validation, and performance optimization, it enables consistent and efficient prompt usage across your application.