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 id 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.
The examples on this page use the Confident AI SDK. Pulling takes the prompt's id, which you get back whenever you push to the prompt.
Pull Prompt By Version
Pull prompt with its id
Pull your prompt version by providing the prompt's id and the
version:from confident_ai import ConfidentAI client = ConfidentAI() prompt = client.prompt(prompt_id="<PROMPT-ID>") prompt.pull(version="00.00.01")import { ConfidentAI } from "confident-ai"; const client = new ConfidentAI(); const prompt = client.prompt("<PROMPT-ID>"); await prompt.pull({ version: "00.00.01" });Interpolate variables
Now that you have your prompt template, interpolate any dynamic variables you may have defined in your prompt version.
interpolated_prompt = prompt.interpolate(name="Joe")const interpolatedPrompt = prompt.interpolate({ name: "Joe" });# Interpolation is done client-side after pulling the prompt # The API response includes an "interpolationType" field indicating the format: # - "FSTRING": {variable} (default) # - "MUSTACHE": {{variable}} # - "MUSTACHE_WITH_SPACE": {{ variable }} # - "DOLLAR_BRACKETS": ${variable} # - "JINJA": a Jinja template # Replace variables manually based on the interpolationType in your application codeFor example, if this is your prompt version:
{ "role": "system", "content": "You are a helpful assistant called {{ name }}. Speak normally like a human." }And your interpolation type is
{{ variable }}, interpolating the name (e.g. "Joe") would give you this prompt that is ready for use:{ "role": "system", "content": "You are a helpful assistant called Joe. Speak normally like a human." }You are a helpful assistant called {{ name }}. Speak normally like a human.And your interpolation type is
{{ variable }}, interpolating the name (e.g. “Joe”) would give you this prompt that is ready for use:You are a helpful assistant called Joe. Speak normally like a human.interpolated_prompt = prompt.interpolate(name="Joe")const interpolatedPrompt = prompt.interpolate({ name: "Joe" });# Interpolation is done client-side after pulling the prompt # The API response includes an "interpolationType" field indicating the format: # - "FSTRING": {variable} (default) # - "MUSTACHE": {{variable}} # - "MUSTACHE_WITH_SPACE": {{ variable }} # - "DOLLAR_BRACKETS": ${variable} # - "JINJA": a Jinja template # Replace variables manually based on the interpolationType in your application codeAnd 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.Use interpolated prompt
By now you should have an interpolated prompt version, for example:
{ "role": "system", "content": "You are a helpful assistant called Joe. Speak normally like a human." }Which you can use to generate text from your LLM provider of choice. Here are some examples with OpenAI:
main.py from confident_ai import ConfidentAI from openai import OpenAI client = ConfidentAI() prompt = client.prompt(prompt_id="<PROMPT-ID>") prompt.pull() interpolated_prompt = prompt.interpolate() # interpolate prompt response = OpenAI().chat.completions.create( model="gpt-4o-mini", messages=[message.model_dump(exclude_none=True) for message in interpolated_prompt], ) print(response.choices[0].message.content)index.ts import { ConfidentAI } from "confident-ai"; import { OpenAI } from "openai"; const client = new ConfidentAI(); const prompt = client.prompt("<PROMPT-ID>"); await prompt.pull(); const interpolatedPrompt = prompt.interpolate({}); // interpolate prompt const openai = new OpenAI(); const response = await openai.chat.completions.create({ model: "gpt-4o-mini", messages: interpolatedPrompt as any[], }); console.log(response.choices[0].message.content);First, pull the prompt from Confident AI:
GET/v2/prompts/{promptId}/versions/{version} curl -X GET "https://api.confident-ai.com/v2/prompts/{promptId}/versions/{version}" \ -H "CONFIDENT_API_KEY: <PROJECT-API-KEY>"Then, interpolate the variables and use the interpolated prompt with OpenAI:
curl -X POST "https://api.openai.com/v1/chat/completions" \ -H "Authorization: Bearer YOUR_OPENAI_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "model": "gpt-4.1", "messages": <YOUR-INTERPOLATED-PROMPT> }'You are a helpful assistant called Joe. Speak normally like a human.Which you can use to generate text from your LLM provider of choice. Here are some examples with OpenAI:
main.py from confident_ai import ConfidentAI from openai import OpenAI client = ConfidentAI() prompt = client.prompt(prompt_id="<PROMPT-ID>") prompt.pull() interpolated_prompt = prompt.interpolate() # interpolate prompt response = OpenAI().chat.completions.create( model="gpt-4o-mini", messages=[{"role": "system", "content": interpolated_prompt}], ) print(response.choices[0].message.content)index.ts import { ConfidentAI } from "confident-ai"; import { OpenAI } from "openai"; const client = new ConfidentAI(); const prompt = client.prompt("<PROMPT-ID>"); await prompt.pull(); const interpolatedPrompt = prompt.interpolate({}); // interpolate prompt const openai = new OpenAI(); const response = await openai.chat.completions.create({ model: "gpt-4o-mini", messages: [{ role: "system", content: interpolatedPrompt as string }], }); console.log(response.choices[0].message.content);First, pull the prompt from Confident AI:
GET/v2/prompts/{promptId}/versions/{version} curl -X GET "https://api.confident-ai.com/v2/prompts/{promptId}/versions/{version}" \ -H "CONFIDENT_API_KEY: <PROJECT-API-KEY>"Then, interpolate the variables and use the interpolated prompt with OpenAI:
curl -X POST "https://api.openai.com/v1/chat/completions" \ -H "Authorization: Bearer YOUR_OPENAI_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "model": "gpt-4.1", "messages": <YOUR-INTERPOLATED-PROMPT> }'
You can also fetch all the versions associated with a prompt as shown below:
from confident_ai import ConfidentAI
client = ConfidentAI()
result = client.prompts.get_versions(prompt_id="<PROMPT-ID>")Pull Prompts By Label
You can also pull specific versions of prompts using the label you assign to the versions on the platform.
from confident_ai import ConfidentAI
client = ConfidentAI()
prompt = client.prompt(prompt_id="<PROMPT-ID>")
prompt.pull(label="staging")import { ConfidentAI } from "confident-ai";
const client = new ConfidentAI();
const prompt = client.prompt("<PROMPT-ID>");
await prompt.pull({ label: "staging" });You must manually label each prompt version before pulling it. Click here to learn how to do so.
Pull Prompts By Commit
You can also pull specific snapshots of prompts using its id and the commit hash.
from confident_ai import ConfidentAI
client = ConfidentAI()
prompt = client.prompt(prompt_id="<PROMPT-ID>")
prompt.pull()import { ConfidentAI } from "confident-ai";
const client = new ConfidentAI();
const prompt = client.prompt("<PROMPT-ID>");
await prompt.pull();You can also fetch all the commits associated with a prompt as shown below:
from confident_ai import ConfidentAI
client = ConfidentAI()
result = client.prompts.get_commits(prompt_id="<PROMPT-ID>")Pull Prompts By Branch
You can also pull specific snapshots of prompts using its id and the branch name.
from confident_ai import ConfidentAI
client = ConfidentAI()
prompt = client.prompt(prompt_id="<PROMPT-ID>")
prompt.pull(branch="MY-BRANCH-NAME")import { ConfidentAI } from "confident-ai";
const client = new ConfidentAI();
const prompt = client.prompt("<PROMPT-ID>");
await prompt.pull({ branch: "MY-BRANCH-NAME" });Branch Operations
You can also perform branch operations such as creating a new branch, updating a branch name, deleting a branch and listing all branches.
from confident_ai import ConfidentAI
client = ConfidentAI()
result = client.prompts.create_branch(
prompt_id="<PROMPT-ID>",
name="experiment",
)from confident_ai import ConfidentAI
client = ConfidentAI()
result = client.prompts.update_branch(
prompt_id="<PROMPT-ID>",
branch_id="<BRANCH-ID>",
name="experiment-v2",
)from confident_ai import ConfidentAI
client = ConfidentAI()
result = client.prompts.delete_branch(
prompt_id="<PROMPT-ID>",
branch_id="<BRANCH-ID>",
)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.
sequenceDiagram
participant App as Your Application
participant SDK as Confident AI SDK
participant Cache as SDK Cache
participant API as Confident AI API
App->>SDK: Pull Prompt
SDK->>Cache: Check cache
Cache-->>SDK: Cached Prompt Data
SDK-->>App: Prompt Data
Note over Cache,API: Refetching (every 60s)
Cache->>API: Pull prompt
API-->>Cache: Update Prompt CachesequenceDiagram
participant App as Your Application
participant SDK as Confident AI SDK
participant Cache as SDK Cache
participant API as Confident AI API
Note over App,API: Caching Disabled (refresh=0)
App->>SDK: Pull Prompt
SDK->>Cache: Bypass cache
Cache->>API: Pull prompt
API-->>Cache: Prompt Data
Cache-->>SDK: Prompt Data
SDK-->>App: Prompt Data
Note over Cache,API: Direct API call every timeCustomize refresh rate
By default, the cache is refetched every 60 seconds, where the SDK 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.
from confident_ai import ConfidentAI
client = ConfidentAI()
prompt = client.prompt(prompt_id="<PROMPT-ID>")
prompt.pull(refresh=60)
interpolated_prompt = prompt.interpolate(name="Joe")import { ConfidentAI } from "confident-ai";
const client = new ConfidentAI();
const prompt = client.prompt("<PROMPT-ID>");
await prompt.pull({ refresh: 60 });
const interpolatedPrompt = 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.
from confident_ai import ConfidentAI
client = ConfidentAI()
prompt = client.prompt(prompt_id="<PROMPT-ID>")
prompt.pull(refresh=0)
interpolated_prompt = prompt.interpolate(name="Joe")import { ConfidentAI } from "confident-ai";
const client = new ConfidentAI();
const prompt = client.prompt("<PROMPT-ID>");
await prompt.pull({ refresh: 0 });
const interpolatedPrompt = 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.).
from confident_ai import ConfidentAI
from openai import OpenAI
client = ConfidentAI()
prompt = client.prompt(prompt_id="<PROMPT-ID>")
prompt.pull()
interpolated_prompt = prompt.interpolate()
settings = prompt.model_settings
# Use model settings (provider, name, parameters) in your OpenAI call
response = OpenAI().chat.completions.create(
model=settings.name,
messages=[message.model_dump(exclude_none=True) for message in interpolated_prompt],
temperature=settings.temperature,
max_tokens=settings.max_tokens,
top_p=settings.top_p,
frequency_penalty=settings.frequency_penalty,
presence_penalty=settings.presence_penalty,
stop=settings.stop_sequence,
)
print(response.choices[0].message.content)import { ConfidentAI } from "confident-ai";
import { OpenAI } from "openai";
const client = new ConfidentAI();
const prompt = client.prompt("<PROMPT-ID>");
await prompt.pull();
const interpolatedPrompt = prompt.interpolate({});
const settings = prompt.modelSettings!;
// Use model settings (provider, name, parameters) in your OpenAI call
const openai = new OpenAI();
const response = await openai.chat.completions.create({
model: settings.name!,
messages: interpolatedPrompt as any[],
temperature: settings.temperature,
max_tokens: settings.maxTokens,
top_p: settings.topP,
frequency_penalty: settings.frequencyPenalty,
presence_penalty: settings.presencePenalty,
stop: settings.stopSequence,
});
console.log(response.choices[0].message.content);Using output type
After pulling a prompt, you can access the output configuration via the output_type and output_schema properties. output_schema is JSON Schema, so you can pass it straight to your model provider's structured output option. This is useful when you want to enforce structured outputs from your LLM.
from confident_ai import ConfidentAI
from confident_ai.prompts import PromptOutputType
from openai import OpenAI
client = ConfidentAI()
prompt = client.prompt(prompt_id="<PROMPT-ID>")
prompt.pull()
interpolated_prompt = prompt.interpolate()
response_format = None
if prompt.output_type == PromptOutputType.JSON:
response_format = {"type": "json_object"}
elif prompt.output_type == PromptOutputType.SCHEMA:
response_format = {
"type": "json_schema",
"json_schema": {"name": "output", "schema": prompt.output_schema},
}
response = OpenAI().chat.completions.create(
model="gpt-4o",
messages=[message.model_dump(exclude_none=True) for message in interpolated_prompt],
response_format=response_format,
)
print(response.choices[0].message.content)import { ConfidentAI } from "confident-ai";
import { PromptOutputType } from "confident-ai/prompts";
import { OpenAI } from "openai";
const client = new ConfidentAI();
const prompt = client.prompt("<PROMPT-ID>");
await prompt.pull();
const interpolatedPrompt = prompt.interpolate({});
const responseFormat =
prompt.outputType === PromptOutputType.SCHEMA
? {
type: "json_schema" as const,
json_schema: { name: "output", schema: prompt.outputSchema },
}
: prompt.outputType === PromptOutputType.JSON
? { type: "json_object" as const }
: undefined;
const openai = new OpenAI();
const response = await openai.chat.completions.create({
model: "gpt-4o",
messages: interpolatedPrompt as any[],
response_format: responseFormat,
});
console.log(response.choices[0].message.content);curl -X GET "https://api.confident-ai.com/v2/prompts/{promptId}/versions/{version}" \
-H "CONFIDENT_API_KEY: <PROJECT-API-KEY>"The response's outputType says what the prompt asks the model to return, and outputSchema holds its JSON Schema when that's SCHEMA.
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", ...}, withoutput_schemaas the schema)
Using tools
After pulling a prompt, you can access the tools its commit pins via the tools property. Each tool contains:
- name: The name of the tool
- description: A description of what the tool does
- schema: The JSON Schema of the tool's input (
schema_in Python) - mode: The tool mode (
ALLOW_ADDITIONAL,NO_ADDITIONAL, orSTRICT) - id and version: The tool, and the version of it the commit pins
from confident_ai import ConfidentAI
from confident_ai.common import ToolMode
from openai import OpenAI
client = ConfidentAI()
prompt = client.prompt(prompt_id="<PROMPT-ID>")
prompt.pull()
interpolated_prompt = prompt.interpolate()
# Convert prompt tools to OpenAI format
openai_tools = [
{
"type": "function",
"function": {
"name": tool.name,
"description": tool.description,
"parameters": tool.schema_,
"strict": tool.mode == ToolMode.STRICT,
},
}
for tool in prompt.tools or []
]
# Use tools in your OpenAI call
response = OpenAI().chat.completions.create(
model="gpt-4o",
messages=[message.model_dump(exclude_none=True) for message in interpolated_prompt],
tools=openai_tools,
)
print(response.choices[0].message)import { ConfidentAI } from "confident-ai";
import { ToolMode } from "confident-ai/common";
import { OpenAI } from "openai";
const client = new ConfidentAI();
const prompt = client.prompt("<PROMPT-ID>");
await prompt.pull();
const interpolatedPrompt = prompt.interpolate({});
// Convert prompt tools to OpenAI format
const openaiTools = (prompt.tools ?? []).map((tool) => ({
type: "function" as const,
function: {
name: tool.name,
description: tool.description ?? undefined,
parameters: tool.schema,
strict: tool.mode === ToolMode.STRICT,
},
}));
// Use tools in your OpenAI call
const openai = new OpenAI();
const response = await openai.chat.completions.create({
model: "gpt-4o",
messages: interpolatedPrompt as any[],
tools: openaiTools,
});
console.log(response.choices[0].message);Using images
Images in a prompt come back as [CONFIDENT:IMAGE:<url>] markers, each holding a signed link. parse_multimodal splits the text into strings and Media in order, so you can build the content parts your MLLM of choice expects. Here's how you'd build them for openai:
from confident_ai import ConfidentAI, Media, parse_multimodal
client = ConfidentAI()
prompt = client.prompt(prompt_id="<PROMPT-ID>")
prompt.pull()
content = []
for part in parse_multimodal(prompt.interpolate()):
if isinstance(part, Media):
content.append({"type": "image_url", "image_url": {"url": part.url}})
else:
content.append({"type": "text", "text": part})import { ConfidentAI, Media, parseMultimodal } from "confident-ai";
const client = new ConfidentAI();
const prompt = client.prompt("<PROMPT-ID>");
await prompt.pull();
const content = parseMultimodal(prompt.interpolate({}) as string).map((part) =>
part instanceof Media
? { type: "image_url", image_url: { url: part.url } }
: { type: "text", text: part },
);curl -X GET "https://api.confident-ai.com/v2/prompts/{promptId}/versions/{version}" \
-H "CONFIDENT_API_KEY: <PROJECT-API-KEY>"The prompt's text or messages carry its images as [CONFIDENT:IMAGE:<url>] markers. Parse the markers to fetch each url, and use it soon after pulling, since the links are signed and expire.
This example is for a text prompt. For a messages prompt, parse each message's content the same way.
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 Confident API
- Logging prompts as a hyperparameter during evaluation
In Python these evals run locally with deepeval, so pull the prompt with deepeval's Prompt (as in the tracing example below) rather than the Confident AI SDK. In TypeScript and over the API they run remotely, so pull the prompt with the Confident AI SDK and log it by its id and type.
Simply add the pulled prompt instance as a free-form key-value pair to the hyperparameters argument in the evaluate() function
evaluate(
...
hyperparameters={
"Model": "YOUR-MODEL",
"Prompt": prompt,
},
)Simply pass the pulled prompt's id and type as a key-value pair in the hyperparameters argument when you run evals
await client.evaluate.runEvals("YOUR-COLLECTION-NAME", testCases, {
Model: "YOUR-MODEL",
Prompt: { id: prompt.id!, type: prompt.type! },
});curl -X POST "https://api.confident-ai.com/v2/evaluate" \
-H "CONFIDENT_API_KEY: <PROJECT-API-KEY>" \
-H "Content-Type: application/json" \
-d '{
"metricCollection": "Collection Name",
"testCases": [
{
"input": "How tall is mount everest?",
"actualOutput": "No clue, pretty tall I guess?",
"expectedOutput": "Mount Everest is 8,848 metres tall.",
"retrievalContext": [
"Everest is 8,848 metres tall."
],
"toolsCalled": [
{
"name": "get_landmark_info",
"type": "FUNCTION",
"description": "This tool gives information about a mountain.",
"inputParameters": {
"mountain": "Everest"
},
"output": "8,848 metres",
"reasoning": "The user asked for the height of a mountain."
}
],
"expectedTools": [
{
"name": "get_landmark_info",
"type": "FUNCTION",
"description": "This tool gives information about a mountain.",
"inputParameters": {
"mountain": "Everest"
},
"output": "8,848 metres",
"reasoning": "The user asked for the height of a mountain."
}
],
"context": [
"Everest is 8,848 metres tall."
],
"tokenCost": 0.002,
"inputTokenCount": 24,
"outputTokenCount": 12,
"name": "everest-height",
"flaky": false,
"imagesMapping": {
"summit": {
"url": "https://example.com/everest.png",
"local": false
}
},
"additionalMetadata": {
"region": "Nepal"
},
"customColumnKeyValues": {
"team": "search"
},
"tags": [
"geography"
]
}
],
"hyperparameters": {
"model": "gpt-4o-mini"
},
"identifier": "run-399-102"
}'This will automatically attribute the prompt used during this test run, which will allow you get detailed insights in the Confident AI platform.
Tracing
Associating prompts with LLM traces and spans is a great way to determine which prompts performs best in production.
Setup tracing
Attach the
@observedecorator to functions/methods that make up your agent, and specify typellmfor your LLM-calling functions.main.py from deepeval.tracing import observe @observe(type="llm", model="gpt-4.1") def your_llm_component(): ...Pull and interpolate prompt
Pull and interpolate the prompt version to use it for LLM generation.
main.py from deepeval.tracing import observe from deepeval.prompt import Prompt from openai import OpenAI @observe(type="llm", model="gpt-4.1") def your_llm_component(): prompt = Prompt(alias="YOUR-PROMPT-ALIAS") prompt.pull() interpolated_prompt = prompt.interpolate(name="Joe") response = OpenAI().chat.completions.create(model="gpt-4o-mini", messages=interpolated_prompt) return response.choices[0].message.contentExecute your function
Then simply provide the prompt to the
update_llm_spanfunction.main.py from deepeval.tracing import observe, update_llm_span from deepeval.prompt import Prompt from openai import OpenAI @observe(type="llm", model="gpt-4.1") def your_llm_component(): prompt = Prompt(alias="YOUR-PROMPT-ALIAS") prompt.pull() interpolated_prompt = prompt.interpolate(name="Joe") response = OpenAI().chat.completions.create(model="gpt-4o-mini", messages=interpolated_prompt) update_llm_span(prompt=prompt) return response.choices[0].message.contentThis will automatically attribute the prompt used to the LLM span.
Switching Projects
You can pull and manage your prompts in any project by using that project's API key.
- For default usage, set
CONFIDENT_PROJ_API_KEYas an environment variable. - To target a specific project, pass its key as
project_api_keywhen creating the client.
from confident_ai import ConfidentAI
client = ConfidentAI(project_api_key="<PROJECT-API-KEY>")import { ConfidentAI } from "confident-ai";
const client = new ConfidentAI({ projectApiKey: "<PROJECT-API-KEY>" });A client keeps the key it was created with, so to work across several projects in one script, create one client per project.
Next Steps
Now that you can pull prompts into your app, learn how to push them programmatically or run evaluations.
Automate Prompt Management
Push and manage prompts programmatically via the Confident API.
Run Evaluations
Evaluate your LLM app with metrics and datasets.
Last updated on