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 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 map:

Response Object

The Execute method returns a PromptResponse struct with the following fields:

Response Fields

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 when executing prompts.
Use the same subject (e.g., user ID) across prompt executions and metric recording for the same subject or session.
Always implement error handling with fallback behavior to ensure your application continues working even if the API fails.
While variables accept map[string]interface{}, consider wrapping in helper functions for type safety.
For expensive or frequently-used prompts, consider caching responses to reduce API calls and latency.
Store RequestID values for debugging and support purposes.
Use Go’s defer keyword for any cleanup operations needed after API calls.

Next Steps

Recording Metrics

Learn how to track metrics for your prompts

A/B Testing

Set up A/B tests with multiple versions