Skip to main content

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.
This API is currently in Early Access. While we’re excited to share it with you, please be aware that it may undergo significant changes, including breaking changes, as we continue development. We’ll do our best to minimize disruptions, but cannot guarantee long-term backward compatibility during this phase. We value your feedback as we refine and improve the API experience.

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

  1. Always cache prompts after retrieval: Update your local cache whenever you successfully retrieve a prompt.
  1. Implement exponential backoff: When the API is unavailable, implement exponential backoff for retries:
  1. 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 models
  • LLMProvider.AZURE_OPENAI: Azure OpenAI models
  • LLMProvider.AWS_BEDROCK: AWS Bedrock models
  • LLMProvider.VERTEX_AI: Google Vertex AI models
  • LLMProvider.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 retrieve
  • version_id: (Optional) Specific version ID to retrieve
  • version_label: (Optional) Version label to retrieve (e.g., “production”, “staging”)
Examples:
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.id is None: Creates a NEW prompt (even if name matches an existing prompt)
  • If prompt.id is 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)

IMPORTANT: To update a prompt and create a new version while keeping the same name, you must follow these steps:
  1. Pull the existing prompt first - This populates the id field, which is required for versioning
  2. Modify the prompt object - Change messages, model, description, or any other properties
  3. Push the updated prompt - This creates a new version with the same name
Here’s why this workflow is necessary:
  • When you call push_prompt() with a prompt that has id=None, it creates a NEW prompt (even if the name matches)
  • When you call push_prompt() with a prompt that has an id set, it creates a NEW VERSION of the existing prompt (keeping the same name)
  • The pull_prompt() method is what populates the id field from the Prompt Hub
Complete Example:
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.
Common Mistakes to Avoid:

Using Different Variable Formats

Troubleshooting Common Issues

  1. Authentication Errors: Ensure your space_id and api_key are correct
  2. Prompt Not Found: Check that the prompt name matches exactly (case-sensitive)
  3. Formatting Errors: Verify that your variables match the placeholders in the prompt
  4. Update Not Working / Creating Duplicate Prompts:
    • Make sure you called pull_prompt() first to populate the id field
    • If prompt.id is None when you push, it will create a NEW prompt instead of a new version
    • Always follow the workflow: pull → modify → push