Pull Prompts

Learn how to test and use prompts in your LLM app

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 push method in the deepeval Python 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

1

Pull prompt with alias

Pull your prompt version by providing the alias you’ve defined:

1from deepeval.prompt import Prompt
2
3prompt = Prompt(alias="YOUR-PROMPT-ALIAS")
4prompt.pull(version="latest")

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.

1prompt.pull(version="00.00.01")
2

Interpolate variables

Now that you have your prompt template, interpolate any dynamic variables you may have defined in your prompt version.

1interpolated_prompt = prompt.interpolate(name="Joe")

For example, if this is your prompt version:

1{
2 "role": "system",
3 "content": "You are a helpful assistant called {{ name }}. Speak normally like a human."
4}

And your interpolation type is {{ variable }}, interpolating the name (e.g. “Joe”) would give you this prompt that is ready for use:

1{
2 "role": "system",
3 "content": "You are a helpful assistant called Joe. Speak normally like a human."
4}

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.

3

Use interpolated prompt

By now you should have an interpolated prompt version, for example:

1{
2 "role": "system",
3 "content": "You are a helpful assistant called Joe. Speak normally like a human."
4}

Which you can use to generate text from your LLM provider of choice. Here are some examples with OpenAI:

main.py
1from deepeval.prompt import Prompt
2from openai import OpenAI
3
4prompt = Prompt(alias="YOUR-PROMPT-ALIAS")
5prompt.pull()
6interpolated_prompt = prompt.interpolate() # interpolate prompt
7
8response = OpenAI().chat.completions.create(
9 model="gpt-4o-mini",
10 messages=interpolated_prompt
11)
12
13print(response.choices[0].message.content)

You can also fetch all the versions associated with a prompt as shown below:

1from deepeval.prompt import Prompt
2
3prompt = Prompt(alias="YOUR-PROMPT-ALIAS")
4commits = prompt._get_versions()

Pull Prompts By Label

You can also pull specific versions of prompts using the label you assign to the versions on the platform.

1from deepeval.prompt import Prompt
2
3prompt = Prompt(alias="YOUR-PROMPT-ALIAS")
4prompt.pull(label="staging")

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.

1from deepeval.prompt import Prompt
2
3prompt = Prompt(alias="YOUR-PROMPT-ALIAS")
4prompt.pull()

By default, Confident AI will return the most recent commit of your prompt. However, you can also specify the hash to override this behavior.

1prompt.pull(hash="bab04ce")

You can also fetch all the commits associated with a prompt as shown below:

1from deepeval.prompt import Prompt
2
3prompt = Prompt(alias="YOUR-PROMPT-ALIAS")
4commits = prompt._get_commits()

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.

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.

main.py
1from deepeval.prompt import Prompt
2
3prompt = Prompt(alias="YOUR-PROMPT-ALIAS")
4prompt.pull(refresh=60)
5interpolated_prompt = prompt.interpolate(name="Joe")

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.

main.py
1from deepeval.prompt import Prompt
2
3prompt = Prompt(alias="YOUR-PROMPT-ALIAS")
4prompt.pull(refresh=0)
5interpolated_prompt = prompt.interpolate(name="Joe")

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.).

main.py
1from deepeval.prompt import Prompt
2from openai import OpenAI
3
4prompt = Prompt(alias="YOUR-PROMPT-ALIAS")
5prompt.pull()
6interpolated_prompt = prompt.interpolate()
7settings = prompt.model_settings
8
9# Use model settings (provider, name, parameters) in your OpenAI call
10response = OpenAI().chat.completions.create(
11 model=settings.name,
12 messages=interpolated_prompt,
13 temperature=settings.temperature,
14 max_tokens=settings.max_tokens,
15 top_p=settings.top_p,
16 frequency_penalty=settings.frequency_penalty,
17 presence_penalty=settings.presence_penalty,
18 stop=settings.stop_sequence,
19)
20
21print(response.choices[0].message.content)

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.

main.py
1from deepeval.prompt import Prompt
2from deepeval.prompt.api import OutputType
3from openai import OpenAI
4
5prompt = Prompt(alias="YOUR-PROMPT-ALIAS")
6prompt.pull()
7interpolated_prompt = prompt.interpolate()
8
9# Build response_format based on output type
10response_format = None
11if prompt.output_type == OutputType.JSON:
12 response_format = {"type": "json_object"}
13elif prompt.output_type == OutputType.SCHEMA:
14 response_format = {
15 "type": "json_schema",
16 "json_schema": prompt.output_schema
17 }
18
19# Use output type in your OpenAI call
20response = OpenAI().chat.completions.create(
21 model="gpt-4o",
22 messages=interpolated_prompt,
23 response_format=response_format,
24)
25
26print(response.choices[0].message.content)

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, or STRICT)
main.py
1from deepeval.prompt import Prompt
2from openai import OpenAI
3
4prompt = Prompt(alias="YOUR-PROMPT-ALIAS")
5prompt.pull()
6interpolated_prompt = prompt.interpolate()
7
8# Convert prompt tools to OpenAI format
9openai_tools = [
10 {
11 "type": "function",
12 "function": {
13 "name": tool.name,
14 "description": tool.description,
15 "parameters": tool.input_schema,
16 "strict": tool.mode == "STRICT",
17 },
18 }
19 for tool in prompt.tools
20]
21
22# Use tools in your OpenAI call
23response = OpenAI().chat.completions.create(
24 model="gpt-4o",
25 messages=interpolated_prompt,
26 tools=openai_tools,
27)
28
29print(response.choices[0].message)

Using images

For prompts containing images, here’s how you would parse it and pass it for use in your MLLM of choice:

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.

1from deepeval.prompt import Prompt
2from deepeval.utils import convert_to_multi_modal_array
3
4prompt = Prompt(alias="YOUR-PROMPT-ALIAS")
5prompt.pull()
6
7multimodal_array = convert_to_multi_modal_array(prompt.text)

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:

1messages = []
2for element in multimodal_array:
3 if isinstance(element, str):
4 messages.append({"type": "text", "text": element})
5 elif isinstance(element, MLLMImage):
6 if element.url:
7 messages.append(
8 {
9 "type": "image_url",
10 "image_url": {"url": element.url},
11 }
12 )

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

Simply add the pulled prompt instance as a free-form key-value pair to the hyperparameters argument in the evaluate() function

1evaluate(
2 ...
3 hyperparameters={
4 "Model": "YOUR-MODEL",
5 "Prompt": prompt,
6 },
7)

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.

1

Setup tracing

Attach the @observe decorator to functions/methods that make up your agent, and specify type llm for your LLM-calling functions.

main.py
1from deepeval.tracing import observe
2
3@observe(type="llm", model="gpt-4.1")
4def your_llm_component():
5 ...

Specifying the type is necessary because logging prompts is only available for LLM spans.

2

Pull and interpolate prompt

Pull and interpolate the prompt version to use it for LLM generation.

main.py
1from deepeval.tracing import observe
2from deepeval.prompt import Prompt
3from openai import OpenAI
4
5@observe(type="llm", model="gpt-4.1")
6def your_llm_component():
7 prompt = Prompt(alias="YOUR-PROMPT-ALIAS")
8 prompt.pull()
9 interpolated_prompt = prompt.interpolate(name="Joe")
10 response = OpenAI().chat.completions.create(model="gpt-4o-mini", messages=interpolated_prompt)
11 return response.choices[0].message.content
3

Execute your function

Then simply provide the prompt to the update_llm_span function.

main.py
1from deepeval.tracing import observe, update_llm_span
2from deepeval.prompt import Prompt
3from openai import OpenAI
4
5@observe(type="llm", model="gpt-4.1")
6def your_llm_component():
7 prompt = Prompt(alias="YOUR-PROMPT-ALIAS")
8 prompt.pull()
9 interpolated_prompt = prompt.interpolate(name="Joe")
10 response = OpenAI().chat.completions.create(model="gpt-4o-mini", messages=interpolated_prompt)
11 update_llm_span(prompt=prompt)
12 return response.choices[0].message.content

Remember to pull the prompt before updating the span, otherwise the prompt will not be logged.

This will automatically attribute the prompt used to the LLM span.

Switching Projects

You can pull and manage your prompts in any project by configuring a CONFIDENT_API_KEY.

  • For default usage, set CONFIDENT_API_KEY as an environment variable.
  • To target a specific project, pass a confident_api_key directly when creating the Prompt object.
1from deepeval.prompt import Prompt, PromptMessage
2
3prompt = Prompt(
4 alias="YOUR-PROMPT-ALIAS",
5 confident_api_key="confident_us...",
6)

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.