Basic Usage
Execute a prompt using its key:Using Variables
Pass dynamic variables to your prompts:Using Subject for A/B Testing
Provide a subject to enable deterministic A/B testing:The same subject always gets the same version. This ensures users have a consistent experience.
Subject Types
Subject can be either a string or a dictionary:Response Object
Theexecute method returns a response object with the following attributes:
Response Attributes
Error Handling
Handle common errors when executing prompts:Common Patterns
Pattern 1: Dynamic Email Generation
Pattern 2: Chatbot Responses
Pattern 3: Content Generation
Pattern 4: Fallback Handling
Best Practices
Always use subject identification for A/B testing
Always use subject identification for A/B testing
If you want to track metrics or run A/B tests, always provide subject identification when executing prompts.
Use consistent subject
Use consistent subject
Use the same subject (e.g., user ID) across prompt executions and metric recording for the same user or session.
Handle errors gracefully
Handle errors gracefully
Always implement error handling with fallback behavior to ensure your application continues working even if the API fails.
Cache responses when appropriate
Cache responses when appropriate
For expensive or frequently-used prompts, consider caching responses to reduce API calls and latency.
Log request IDs
Log request IDs
Store
request_id values for debugging and support purposes.Next Steps
Recording Metrics
Learn how to track metrics for your prompts
A/B Testing
Set up A/B tests with multiple versions

