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:

  1. Templates - Reusable prompt patterns with variable placeholders
  2. Input Types - Type definitions for template variables ensuring proper usage
  3. 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:

1template = "Hello {name}, welcome to {company}!"
2input_types = {
3 "name": "string",
4 "company": "string"
5}

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:

  1. Base templates for common patterns
  2. Specialized templates that extend base templates
  3. Override capabilities for customization

Using Prompts

Basic Usage

Templates can be used directly with input values:

1greeting = prompts.get(
2 name="welcome_template",
3 inputs={
4 "name": "John",
5 "company": "Acme Inc"
6 }
7)
8# -> "Hello John, welcome to Acme Inc!"

System Prompts

Special system prompts can be defined for consistent AI interactions across your application. These provide:

  1. Base context for AI models
  2. Standard instruction sets
  3. Common constraints or rules

Task Prompts

Task-specific prompts build on system prompts to:

  1. Define specific operations or questions
  2. Include relevant context
  3. Guide model responses

Performance Optimization

The prompt system includes built-in performance features:

  1. Template Caching - Frequently used templates are cached in memory
  2. Render Caching - Common prompt/input combinations are cached
  3. 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.

Built with