Arize Prompt Hub SDK
The Arize Prompt Hub SDK provides a Python interface for managing and using prompts with the Arize AI platform. This SDK allows you to create, retrieve, update, and use prompts with various LLM providers.Overview
Prompt Hub enables you to:- Create and store prompt templates in your Arize space
- Retrieve prompts for use in your applications
- Update existing prompts with new versions
- Track prompt versions and changes
Quick Start
OpenAI Example
Vertex AI Example
Error Handling and Fallback Strategies
When working with the Prompt Hub API in production environments, it’s important to implement fallback mechanisms in case the API becomes temporarily unavailable.Local Cache Fallback
You can implement a local cache of your prompts to ensure your application continues to function even if the Prompt Hub API is unreachable:Best Practices for Resilient Applications
- Always cache prompts after retrieval: Update your local cache whenever you successfully retrieve a prompt.
- Implement exponential backoff: When the API is unavailable, implement exponential backoff for retries:
- Periodically sync your cache: Implement a background job to periodically sync your cache with the latest prompts from the API.
Core Components
ArizePromptClient
The main client for interacting with the Arize Prompt Hub.Prompt
Represents a prompt template with associated metadata.LLMProvider
Enum for supported LLM providers:LLMProvider.OPENAI: OpenAI modelsLLMProvider.AZURE_OPENAI: Azure OpenAI modelsLLMProvider.AWS_BEDROCK: AWS Bedrock modelsLLMProvider.VERTEX_AI: Google Vertex AI modelsLLMProvider.CUSTOM: Custom provider
PromptInputVariableFormat
Enum for specifying how input variables are formatted in prompts:PromptInputVariableFormat.F_STRING: Single curly braces ({variable_name})PromptInputVariableFormat.MUSTACHE: Double curly braces ({{variable_name}})
API Reference
ArizePromptClient Methods
pull_prompts()
Retrieves all prompts in the space.
pull_prompt(prompt_name, version_id=None, version_label=None)
Retrieves a specific prompt by name, version ID, or version label. Returns the prompt with the id field populated, which is REQUIRED for updating the prompt.
Parameters:
prompt_name: The name of the prompt to retrieveversion_id: (Optional) Specific version ID to retrieveversion_label: (Optional) Version label to retrieve (e.g., “production”, “staging”)
Version labels are tags that can be applied to prompt versions (like “production”, “staging”, “v1.0”) to make them easier to identify and retrieve. Version labels are currently managed through the Arize UI, not the Python SDK.
push_prompt(prompt, commit_message=None)
Creates a new prompt or updates an existing one by creating a new version.
Behavior:
- If
prompt.idisNone: Creates a NEW prompt (even if name matches an existing prompt) - If
prompt.idis set: Creates a NEW VERSION of the existing prompt (keeps same name, preserves version history)
Prompt Methods
format(variables)
Formats the prompt with the given variables for use with an LLM provider.
Examples
Creating and Using a Prompt
Updating an Existing Prompt (Creating a New Version with the Same Name)
Here’s why this workflow is necessary:- When you call
push_prompt()with a prompt that hasid=None, it creates a NEW prompt (even if the name matches) - When you call
push_prompt()with a prompt that has anidset, it creates a NEW VERSION of the existing prompt (keeping the same name) - The
pull_prompt()method is what populates theidfield from the Prompt Hub
Note on Version Labels:Version labels (like “production”, “staging”, “v1.0”) are tags that can be applied to prompt versions to make them easier to identify and retrieve. You can retrieve a prompt by version label using:Version labels are currently managed through the Arize UI. After creating a new version with
push_prompt(), you can add or update version labels in the Prompt Hub interface.Using Different Variable Formats
Troubleshooting Common Issues
- Authentication Errors: Ensure your
space_idandapi_keyare correct - Prompt Not Found: Check that the prompt name matches exactly (case-sensitive)
- Formatting Errors: Verify that your variables match the placeholders in the prompt
- Update Not Working / Creating Duplicate Prompts:
- Make sure you called
pull_prompt()first to populate theidfield - If
prompt.idisNonewhen you push, it will create a NEW prompt instead of a new version - Always follow the workflow: pull → modify → push
- Make sure you called