Skip to main content

Basic Usage

Execute a prompt using its key:

Using Variables

Pass dynamic variables to your prompts:
Your prompt template in the dashboard:

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

The execute 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

If you want to track metrics or run A/B tests, always provide subject identification when executing prompts.
Use the same subject (e.g., user ID) across prompt executions and metric recording for the same user or session.
Always implement error handling with fallback behavior to ensure your application continues working even if the API fails.
For expensive or frequently-used prompts, consider caching responses to reduce API calls and latency.
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