Pull Prompts
Overview
You can pull a prompt version from Confident AI like how you would pull a dataset. It works by:
- Providing Confident AI with the alias and optionally version of the prompt you wish to retrieve
- Confident AI will provide the non-interpolated version of the prompt
- You will then interpolate the variables in code
You should pull prompts once and save it in memory instead of pulling it everytime you need to use it.
Confident AI uses a versioning system for prompts similar to Git.
- Each new iteration of a prompt is stored as a new commit, you can create commits directly in the platform or by using the
pushmethod in thedeepevalPython or TypeScript SDKs. - Any specific commit can be promoted to a version. Versions act as official checkpoints, making it easier to track stable or production-ready prompts.
- On top of versions, you can assign labels. Labels give a version a clear, human-friendly identifier so you can quickly reference it (for example, “production” or “v1.2-stable”).
Pull Prompt By Version
Pull prompt with alias
Pull your prompt version by providing the alias you’ve defined:
Python
TypeScript
curL
By passing latest instead of a specific version, Confident AI will return the most recent version of your prompt.
However, you can also specify the version to override this behavior.
Interpolate variables
Now that you have your prompt template, interpolate any dynamic variables you may have defined in your prompt version.
Python
TypeScript
curL
For example, if this is your prompt version:
Messages
Text
And your interpolation type is {{ variable }}, interpolating the name (e.g. “Joe”) would give you this prompt that is ready for use:
And if you don’t have any variables, you must still use the interpolate() method to create a copy of your prompt template to be used in your LLM application.
You can also fetch all the versions associated with a prompt as shown below:
Python
Typescript
curL
Pull Prompts By Label
You can also pull specific versions of prompts using the label you assign to the versions on the platform.
Python
TypeScript
curL
You must manually label each prompt version before pulling it. Click here to learn how to do so.
By pulling via labels, you effectively allow users with sufficient permission to “deploy” new versions of your prompt without going through code.
Pull Prompts By Commit
You can also pull specific snapshots of prompts using it’s alias and the commit hash.
Python
TypeScript
curL
By default, Confident AI will return the most recent commit of your prompt.
However, you can also specify the hash to override this behavior.
You can also fetch all the commits associated with a prompt as shown below:
Python
Typescript
curL
How Are Prompts Pulled?
Confident AI automatically caches prompts on the client side to minimize API call latency and ensure prompt availability, which is especially useful in production environments.
Cache
No Cache
Customize refresh rate
By default, the cache is refetched every 60 seconds, where DeepEval will automatically update the cached prompt with the up-to-date version from Confident AI. This can be overridden by setting the refresh parameter to a different value. Fetching is done asynchronously, so it will not block your application.
Python
TypeScript
Configure cache
To disable caching, you can set refresh=0. This will force an API call every time you pull the prompt, which is particularly useful for development and testing.
Python
TypeScript
Advanced Usage
As you learnt in earlier sections, prompts have the additional option to not just version text/messages but also model settings (provider, name, parameters), output type, and tools.
Using model settings
After pulling a prompt, you can access any model settings that were configured for the prompt version via the model_settings property. Model settings include the provider, model name, and model parameters (temperature, max_tokens, etc.).
Python
TypeScript
curL
Model settings are optional. If no model settings were configured for the
prompt version, model_settings will be None.
Using output type
After pulling a prompt, you can access the output configuration via the output_type and output_schema properties. This is useful when you want to enforce structured outputs from your LLM.
Python
TypeScript
curL
The available output types are:
- TEXT - Plain text output (default)
- JSON - JSON formatted output (maps to
{"type": "json_object"}) - SCHEMA - Structured output validated against a schema (maps to
{"type": "json_schema", ...})
Using tools
After pulling a prompt, you can access any tools that were defined in the prompt version via the tools property. Each tool contains:
- name: The name of the tool
- description: A description of what the tool does
- input_schema: The JSON schema defining the tool’s input parameters
- mode: The tool mode (
ALLOW_ADDITIONAL,NO_ADDITIONAL, orSTRICT)
Python
TypeScript
curL
Using images
For prompts containing images, here’s how you would parse it and pass it for use in your MLLM of choice:
Python
TypeScript
curL
Custom
The deepeval python SDK offers a utility method called convert_to_multi_modal_array. This method is useful for converting a string containing images in the [DEEPEVAL:IMAGE:url] format into a list of strings and MLLMImage items.
The multimodal_array here is a list containing strings and MLLMImages, you can loop over this list to construct a messages array with images to pass to your MLLM. Here’s an example showing how to construct messages array for openai:
Confident AI automatically handles any multi-modal conversation when running evals using one of our no-code workflows.
Prompt Association
You can and should definitely associate prompt versions with test runs and traced data for Confident AI to let you know which version of your prompt performs best.
Evals
You can associate a prompt with your evals to get detailed insights on how each prompt and their versions are performing. It works by:
- Pulling prompt via the Evals API
- Logging prompts as a hyperparameter during evaluation
Python
Typescript
curL
Simply add the pulled prompt instance as a free-form key-value pair to the hyperparameters argument in the evaluate() function
This will automatically attribute the prompt used during this test run, which will allow you get detailed insights in the Confident AI platform.
Never ever ever associate the interpolated prompt version - Confident AI will treat it as a string literal and you will not be able to associate prompt versions but instead raw strings (which isn’t helpful at all).
Tracing
Associating prompts with LLM traces and spans is a great way to determine which prompts performs best in production.
Setup tracing
Attach the @observe decorator to functions/methods that make up your agent, and specify type llm for your LLM-calling functions.
Specifying the type is necessary because logging prompts is only available for LLM spans.
Switching Projects
You can pull and manage your prompts in any project by configuring a CONFIDENT_API_KEY.
- For default usage, set
CONFIDENT_API_KEYas an environment variable. - To target a specific project, pass a
confident_api_keydirectly when creating thePromptobject.
When both are provided, the confident_api_key passed to Prompt always takes precedence over the environment variable.
Next Steps
Now that you can pull prompts into your app, learn how to push them programmatically or run evaluations.