Launch Week 3: Five days of launches

Prompts

Every Prompts method in the Confident AI Python and TypeScript SDKs.

Overview

The Confident AI SDK exposes every Prompt method on the platform. This page documents how to call these methods in all supported languages. See the introduction to install the SDK and set your API key.

Prompt

client.prompt() returns a Prompt object that stands for one prompt. This object stores the fields listed below, and passes the prompt's id to every method called on it, so you don't need to pass the id nor the stored fields as arguments.

push is the exception, because it sends the stored fields rather than calling a route that names the id. Open the object with alias to call it.

from confident_ai import ConfidentAI

client = ConfidentAI()

prompt = client.prompt(prompt_id="<PROMPT-ID>")

Properties

These are the fields a Prompt stores. A method that loads the prompt fills them in, and a method that saves it sends whichever of them you have set, so set them before you save and read them after you load.

ParameterTypeDescription
prompt_idOptional[str]The unique id of the prompt.
textOptional[str]This is the text content of the prompt.
aliasOptional[str]This is the alias of the prompt, which is unique within your project.
idOptional[str]This is the id of the commit pulled, generated by Confident AI, not to be confused with the prompt id, the version number, or the commit hash.
hashOptional[str]This is the commit hash of the prompt pulled.
versionOptional[str]The version number of the prompt, present when the commit pulled has been released as a version.
labelOptional[str]The user-defined label of the version pulled, present when the version carries one.
typeOptional[PromptType]See PromptType.
interpolation_typeOptional[PromptInterpolationType]See PromptInterpolationType.
model_settingsOptional[ModelSettings]See ModelSettings.
output_typeOptional[PromptOutputType]See PromptOutputType.
output_schemaOptional[OutputSchema]See OutputSchema.
toolsOptional[List[Tool]]This is the list of tools available to the prompt. See Tool.
messagesOptional[List[PromptMessage]]This is the list of messages that make up the prompt. See PromptMessage.

Methods

Push Prompt

Creates a new commit for the prompt with the given alias, creating the prompt first when it does not exist. Send text for a text prompt or messages for a messages prompt, not both.

from confident_ai import ConfidentAI

client = ConfidentAI()

prompt = client.prompt(alias="greeting")
result = prompt.push(branch="main")

For async mode, call a_push and await it as shown below:

result = await prompt.a_push(...)

Parameters

ParameterTypeDescription
branchOptional[str]The name of the branch to push the new commit to. The branch is created from main when it does not exist yet.

Returns

This method returns an object of type PushPromptResult.

Pull Prompt

Pull the prompt from Confident AI, and keep it current.

Pass at most one of commit, version, label. The commit that comes back is cached on disk and re-pulled in the background every refresh seconds, so editing the prompt on Confident AI reaches a running process without a deploy.

from confident_ai import ConfidentAI

client = ConfidentAI()

prompt = client.prompt(prompt_id="<PROMPT-ID>")
result = prompt.pull(
    commit="<COMMIT>",
    branch="main",
    refresh=60,
    fallback_to_cache=True,
    write_to_cache=True,
    default_to_cache=True,
)

For async mode, call a_pull and await it as shown below:

result = await prompt.a_pull(...)

Parameters

ParameterTypeDescription
commitOptional[str]The hash of the commit to pull. Defaults to latest.
versionOptional[str]The version number of the prompt to pull.
labelOptional[str]The label of the version to pull.
branchOptional[str]The name of the branch to read from. Defaults to main when omitted. Only valid with commit.
refreshOptional[int]How often, in seconds, to re-pull the prompt in the background. 0 turns off the refresh and the cache together, so that every pull calls the API — which is what you want while you are still editing the prompt. Defaults to 60.
fallback_to_cacheboolServe the cached commit when the API cannot be reached, instead of raising. Defaults to True.
write_to_cacheboolWrite the pulled commit to the cache. The background refresh writes it either way. Defaults to True.
default_to_cacheboolReturn the cached commit when there is one, rather than waiting for the API. Defaults to True.

Returns

This method returns an object of type Prompt.

Interpolate Prompt

Render the prompt's template with values, without calling the API.

Returns the interpolated text for a text prompt, and the interpolated messages for a messages prompt.

from confident_ai import ConfidentAI

client = ConfidentAI()

prompt = client.prompt(prompt_id="<PROMPT-ID>")
prompt.pull()
result = prompt.interpolate()

Parameters

ParameterTypeDescription
**valuesAny—

Returns

This method returns an object of type InterpolatedPrompt.

Methods (Stateless)

These methods take every argument themselves, so a caller reaches them through client.prompts without opening a Prompt first.

List Prompts

Lists all the prompts in your Confident AI project.

from confident_ai import ConfidentAI

client = ConfidentAI()

result = client.prompts.list()

For async mode, call a_list and await it as shown below:

result = await client.prompts.a_list(...)

Returns

This method returns an object of type PromptList.

Push Text Prompt

Creates a new commit for the prompt with the given alias, creating the prompt first when it does not exist. Send text for a text prompt or messages for a messages prompt, not both.

Pushes a commit to a text prompt. interpolationType defaults to FSTRING when omitted.

from confident_ai import ConfidentAI
from confident_ai.common import ModelProvider
from confident_ai.prompts import ModelSettings
from confident_ai.prompts import OutputSchema
from confident_ai.prompts import OutputSchemaField
from confident_ai.prompts import PromptInterpolationType
from confident_ai.prompts import PromptOutputType
from confident_ai.prompts import PushTextPrompt
from confident_ai.prompts import ReasoningEffort
from confident_ai.prompts import StructuredSchema
from confident_ai.prompts import Tool
from confident_ai.prompts import ToolMode
from confident_ai.prompts import Verbosity

client = ConfidentAI()

result = client.prompts.push(
    prompt=PushTextPrompt(
        text="Hello, {{name}}! How can I help you today?",
        alias="greeting",
        interpolation_type=PromptInterpolationType.MUSTACHE,
        model_settings=ModelSettings(
            provider=ModelProvider.OPEN_AI,
            name="gpt-4o",
            temperature=0.7,
            max_tokens=1024,
            top_p=1,
            top_k=40,
            frequency_penalty=0,
            presence_penalty=0,
            stop_sequence=["\n\nHuman:", "###"],
            reasoning_effort=ReasoningEffort.MINIMAL,
            verbosity=Verbosity.LOW
        ),
        output_type=PromptOutputType.TEXT,
        output_schema=OutputSchema(
            name="Greeting",
            fields=[
                OutputSchemaField(
                    id="<FIELD-ID>",
                    name="greeting",
                    type=...,
                    required=True,
                    parent_id="<PARENT-ID>"
                )
            ]
        ),
        tools=[
            Tool(
                id="<TOOL-ID>",
                name="get_customer_name",
                description="Looks up the customer's name by id.",
                mode=ToolMode.ALLOW_ADDITIONAL,
                structured_schema=StructuredSchema(
                    id="<STRUCTURED-SCHEMA-ID>",
                    name="GetCustomerNameInput",
                    fields=[
                        ...
                    ]
                )
            )
        ],
        branch="main"
    ),
)

For async mode, call a_push and await it as shown below:

result = await client.prompts.a_push(...)

Parameters

ParameterTypeDescription
promptPushPromptRequestRequired. The commit to push. Send text for a text prompt or messages for a messages prompt, never both. The kind must match the existing prompt's type. Pass a PushTextPrompt or a PushMessagesPrompt. See PushPromptRequest.

Returns

This method returns an object of type PushPromptResult.

Push Messages Prompt

Creates a new commit for the prompt with the given alias, creating the prompt first when it does not exist. Send text for a text prompt or messages for a messages prompt, not both.

Pushes a commit to a messages prompt. interpolationType defaults to FSTRING when omitted.

from confident_ai import ConfidentAI
from confident_ai.common import ModelProvider
from confident_ai.prompts import ModelSettings
from confident_ai.prompts import OutputSchema
from confident_ai.prompts import OutputSchemaField
from confident_ai.prompts import PromptInterpolationType
from confident_ai.prompts import PromptOutputType
from confident_ai.prompts import PushMessagesPrompt
from confident_ai.prompts import ReasoningEffort
from confident_ai.prompts import StructuredSchema
from confident_ai.prompts import Tool
from confident_ai.prompts import ToolMode
from confident_ai.prompts import Verbosity

client = ConfidentAI()

result = client.prompts.push(
    prompt=PushMessagesPrompt(
        messages=[
            {"role": "system", "content": "You are a helpful assistant."},
            {
                "role": "user",
                "content": "Hello, {{name}}! How can I help you today?"
            }
        ],
        alias="greeting",
        interpolation_type=PromptInterpolationType.MUSTACHE,
        model_settings=ModelSettings(
            provider=ModelProvider.OPEN_AI,
            name="gpt-4o",
            temperature=0.7,
            max_tokens=1024,
            top_p=1,
            top_k=40,
            frequency_penalty=0,
            presence_penalty=0,
            stop_sequence=["\n\nHuman:", "###"],
            reasoning_effort=ReasoningEffort.MINIMAL,
            verbosity=Verbosity.LOW
        ),
        output_type=PromptOutputType.TEXT,
        output_schema=OutputSchema(
            name="Greeting",
            fields=[
                OutputSchemaField(
                    id="<FIELD-ID>",
                    name="greeting",
                    type=...,
                    required=True,
                    parent_id="<PARENT-ID>"
                )
            ]
        ),
        tools=[
            Tool(
                id="<TOOL-ID>",
                name="get_customer_name",
                description="Looks up the customer's name by id.",
                mode=ToolMode.ALLOW_ADDITIONAL,
                structured_schema=StructuredSchema(
                    id="<STRUCTURED-SCHEMA-ID>",
                    name="GetCustomerNameInput",
                    fields=[
                        ...
                    ]
                )
            )
        ],
        branch="main"
    ),
)

For async mode, call a_push and await it as shown below:

result = await client.prompts.a_push(...)

Parameters

ParameterTypeDescription
promptPushPromptRequestRequired. The commit to push. Send text for a text prompt or messages for a messages prompt, never both. The kind must match the existing prompt's type. Pass a PushTextPrompt or a PushMessagesPrompt. See PushPromptRequest.

Returns

This method returns an object of type PushPromptResult.

Get By Label

Retrieves the prompt version carrying label.

from confident_ai import ConfidentAI

client = ConfidentAI()

result = client.prompts.get_by_label(
    prompt_id="<PROMPT-ID>",
    label="production",
)

For async mode, call a_get_by_label and await it as shown below:

result = await client.prompts.a_get_by_label(...)

Parameters

ParameterTypeDescription
prompt_idstrRequired. The unique id of the prompt.
labelstrRequired. The label of the version to pull.

Returns

This method returns an object of type Prompt.

Get By Commit

Retrieves the prompt commit with the given hash. The commit is looked up on main unless a branch is given.

from confident_ai import ConfidentAI

client = ConfidentAI()

result = client.prompts.get_by_commit(
    prompt_id="<PROMPT-ID>",
    hash="bab04ce",
    branch="main",
)

For async mode, call a_get_by_commit and await it as shown below:

result = await client.prompts.a_get_by_commit(...)

Parameters

ParameterTypeDescription
prompt_idstrRequired. The unique id of the prompt.
hashstrRequired. The hash of the commit to pull.
branchOptional[str]The name of the branch to read from. Defaults to main when omitted.

Returns

This method returns an object of type Prompt.

Get By Version

Retrieves the prompt commit released as version.

from confident_ai import ConfidentAI

client = ConfidentAI()

result = client.prompts.get_by_version(
    prompt_id="<PROMPT-ID>",
    version="00.00.01",
)

For async mode, call a_get_by_version and await it as shown below:

result = await client.prompts.a_get_by_version(...)

Parameters

ParameterTypeDescription
prompt_idstrRequired. The unique id of the prompt.
versionstrRequired. The version number of the prompt to pull.

Returns

This method returns an object of type Prompt.

Types

ModelProvider

This is the provider of the model.

class ModelProvider(Enum):
    OPEN_AI = "OPEN_AI"
    CUSTOM = "CUSTOM"
    CONFIDENT_AI = "CONFIDENT_AI"
    BEDROCK = "BEDROCK"
    ANTHROPIC = "ANTHROPIC"
    GEMINI = "GEMINI"
    X_AI = "X_AI"
    DEEPSEEK = "DEEPSEEK"
    MOONSHOT_AI = "MOONSHOT_AI"
    VERTEX_AI = "VERTEX_AI"
    AZURE = "AZURE"
    MISTRAL = "MISTRAL"
    PERPLEXITY = "PERPLEXITY"
    OPEN_ROUTER = "OPEN_ROUTER"
    PORTKEY = "PORTKEY"
    LITE_LLM = "LITE_LLM"
    TRUE_FOUNDRY = "TRUE_FOUNDRY"
    HUGGING_FACE = "HUGGING_FACE"
    TYPE_SAFE = "TYPE_SAFE"
    FAL = "FAL"

OPEN_AI · CUSTOM · CONFIDENT_AI · BEDROCK · ANTHROPIC · GEMINI · X_AI · DEEPSEEK · MOONSHOT_AI · VERTEX_AI · AZURE · MISTRAL · PERPLEXITY · OPEN_ROUTER · PORTKEY · LITE_LLM · TRUE_FOUNDRY · HUGGING_FACE · TYPE_SAFE · FAL

ModelSettings

This is the model settings the prompt was authored for.

class ModelSettings:
    provider: Optional[ModelProvider] = None
    name: Optional[str] = None
    temperature: Optional[float] = None
    max_tokens: Optional[float] = Field(default=None, alias="maxTokens")
    top_p: Optional[float] = Field(default=None, alias="topP")
    top_k: Optional[float] = Field(default=None, alias="topK")
    frequency_penalty: Optional[float] = Field(default=None, alias="frequencyPenalty")
    presence_penalty: Optional[float] = Field(default=None, alias="presencePenalty")
    stop_sequence: Optional[List[str]] = Field(default=None, alias="stopSequence")
    reasoning_effort: Optional[ReasoningEffort] = Field(default=None, alias="reasoningEffort")
    verbosity: Optional[Verbosity] = None

providerOptional[ModelProvider]

nameOptional[str]

This is the name of the model.

Example: "gpt-4o"

temperatureOptional[float]

This controls randomness in the model's output. Higher values make output more random.

Example: 0.7

max_tokensOptional[float]

This is the maximum number of tokens to generate.

Example: 1024

top_pOptional[float]

This controls diversity via nucleus sampling. Lower values focus on more likely tokens.

Example: 1

top_kOptional[float]

This limits sampling to the K most likely tokens at each step.

Example: 40

frequency_penaltyOptional[float]

This is the penalty for tokens based on their frequency in the text so far.

Example: 0

presence_penaltyOptional[float]

This is the penalty for tokens based on whether they appear in the text so far.

Example: 0

stop_sequenceOptional[List[str]]

This is the sequences where the model will stop generating further tokens.

Example: ["\n\nHuman:","###"]

reasoning_effortOptional[ReasoningEffort]

verbosityOptional[Verbosity]

OutputSchema

This is the output schema definition, used when outputType is SCHEMA.

class OutputSchema:
    name: str
    fields: List[OutputSchemaField]

namestrRequired

This is the name of the output schema.

Example: "Greeting"

fieldsList[OutputSchemaField]Required

This is the array of fields that define the output schema structure.

See OutputSchemaField.

OutputSchemaField

class OutputSchemaField:
    id: Optional[str] = None
    name: str
    type: SchemaDataType
    required: Optional[bool] = None
    parent_id: Optional[str] = Field(default=None, alias="parentId")

idOptional[str]

This is the unique identifier for the schema field. Use it as the parentId of nested fields.

Example: "<FIELD-ID>"

namestrRequired

This is the name of the schema field.

Example: "greeting"

typeSchemaDataTypeRequired

requiredOptional[bool]

This indicates whether the field is required in the output.

Example: true

parent_idOptional[str]

This is the id of the parent field for nested structures, or null for a top-level field.

Prompt

A single commit of a prompt, as pulled by version, commit hash, or label. It carries text when the prompt is a text prompt and messages when it is a messages prompt, never both.

Prompt = Union[
    TextPrompt,
    MessagesPrompt,
]

A Prompt is one of the shapes below. Send the fields of one of them, never a mix of both.

A pulled prompt whose content is a single text template.

class TextPrompt:
    text: str
    alias: str
    id: str
    hash: str
    version: Optional[str] = None
    label: Optional[str] = None
    type: PromptType
    interpolation_type: PromptInterpolationType = Field(alias="interpolationType")
    model_settings: Optional[ModelSettings] = Field(default=None, alias="modelSettings")
    output_type: PromptOutputType = Field(alias="outputType")
    output_schema: Optional[OutputSchema] = Field(default=None, alias="outputSchema")
    tools: Optional[List[Tool]] = None

textstrRequired

This is the text content of the prompt.

Example: "Hello, {{name}}! How can I help you today?"

aliasstrRequired

This is the alias of the prompt, which is unique within your project.

Example: "greeting"

idstrRequired

This is the id of the commit pulled, generated by Confident AI, not to be confused with the prompt id, the version number, or the commit hash.

Example: "<COMMIT-ID>"

hashstrRequired

This is the commit hash of the prompt pulled.

Example: "bab04ce"

versionOptional[str]

The version number of the prompt, present when the commit pulled has been released as a version.

Example: "00.00.01"

labelOptional[str]

The user-defined label of the version pulled, present when the version carries one.

Example: "production"

typePromptTypeRequired

interpolation_typePromptInterpolationTypeRequired

model_settingsOptional[ModelSettings]

output_typePromptOutputTypeRequired

output_schemaOptional[OutputSchema]

toolsOptional[List[Tool]]

This is the list of tools available to the prompt.

See Tool.

PromptInterpolationType

The type of interpolation format used in the prompt to insert dynamic variables.

class PromptInterpolationType(Enum):
    MUSTACHE = "MUSTACHE"
    MUSTACHE_WITH_SPACE = "MUSTACHE_WITH_SPACE"
    FSTRING = "FSTRING"
    DOLLAR_BRACKETS = "DOLLAR_BRACKETS"
    JINJA = "JINJA"

MUSTACHE · MUSTACHE_WITH_SPACE · FSTRING · DOLLAR_BRACKETS · JINJA

PromptList

class PromptList:
    prompts: List[PromptSummary]

promptsList[PromptSummary]Required

This is the list of prompts in your project.

See PromptSummary.

PromptMessage

class PromptMessage:
    role: str
    content: str

rolestrRequired

This is the role of the message, which can be user, assistant, system, or developer.

Example: "user"

contentstrRequired

This is the text content of the message.

Example: "Hello, {{name}}! How can I help you today?"

PromptOutputType

The type of output expected from the prompt.

class PromptOutputType(Enum):
    TEXT = "TEXT"
    JSON = "JSON"
    SCHEMA = "SCHEMA"

TEXT · JSON · SCHEMA

PromptSummary

A prompt as it appears in your project's prompt list, without any version content.

class PromptSummary:
    id: str
    alias: str
    type: PromptType

idstrRequired

This is the unique id of the prompt.

Example: "<PROMPT-ID>"

aliasstrRequired

This is the alias of the prompt, which is unique within your project.

Example: "greeting"

typePromptTypeRequired

PromptType

This is the type of the prompt, which can be either a simple text or a list of messages.

class PromptType(Enum):
    TEXT = "TEXT"
    LIST = "LIST"

TEXT · LIST

PushPromptRequest

The commit to push. Send text for a text prompt or messages for a messages prompt, never both. The kind must match the existing prompt's type.

PushPromptRequest = Union[
    PushTextPrompt,
    PushMessagesPrompt,
]

A PushPromptRequest is one of the shapes below. Send the fields of one of them, never a mix of both.

Pushes a commit to a text prompt. interpolationType defaults to FSTRING when omitted.

class PushTextPrompt:
    text: str
    alias: str
    interpolation_type: Optional[PromptInterpolationType] = Field(default=None, alias="interpolationType")
    model_settings: Optional[ModelSettings] = Field(default=None, alias="modelSettings")
    output_type: Optional[PromptOutputType] = Field(default=None, alias="outputType")
    output_schema: Optional[OutputSchema] = Field(default=None, alias="outputSchema")
    tools: Optional[List[Tool]] = None
    branch: Optional[str] = None

textstrRequired

The text content of the prompt.

Example: "Hello, {{name}}! How can I help you today?"

aliasstrRequired

The alias of the prompt, unique within your project. A new prompt is created when no prompt with this alias exists.

Example: "greeting"

interpolation_typeOptional[PromptInterpolationType]

model_settingsOptional[ModelSettings]

output_typeOptional[PromptOutputType]

output_schemaOptional[OutputSchema]

toolsOptional[List[Tool]]

This is the list of tools to make available to the prompt.

See Tool.

branchOptional[str]

The name of the branch to push the new commit to. The branch is created from main when it does not exist yet.

Example: "main"

PushPromptResult

class PushPromptResult:
    prompt_id: str = Field(alias="promptId")
    hash: str

prompt_idstrRequired

This is the id of the prompt generated by Confident AI, not to be confused with the alias you supplied.

Example: "<PROMPT-ID>"

hashstrRequired

This is the hash of the commit created by this push, not to be confused with a version number.

Example: "bab04ce"

ReasoningEffort

This is the level of reasoning effort for the model.

class ReasoningEffort(Enum):
    MINIMAL = "MINIMAL"
    LOW = "LOW"
    MEDIUM = "MEDIUM"
    HIGH = "HIGH"

MINIMAL · LOW · MEDIUM · HIGH

SchemaDataType

This is the data type of a schema field.

class SchemaDataType(Enum):
    OBJECT = "OBJECT"
    ARRAY = "ARRAY"
    STRING = "STRING"
    FLOAT = "FLOAT"
    INTEGER = "INTEGER"
    BOOLEAN = "BOOLEAN"
    NULL = "NULL"

OBJECT · ARRAY · STRING · FLOAT · INTEGER · BOOLEAN · NULL

StructuredSchema

This is the schema for your tool's input.

class StructuredSchema:
    id: Optional[str] = None
    name: Optional[str] = None
    fields: List[StructuredSchemaField]

idOptional[str]

This is the id of the schema assigned by Confident AI.

Example: "<STRUCTURED-SCHEMA-ID>"

nameOptional[str]

This is the name of the schema.

Example: "GetCustomerNameInput"

fieldsList[StructuredSchemaField]Required

This is the array of fields that define the tool's input structure.

See StructuredSchemaField.

StructuredSchemaField

class StructuredSchemaField:
    id: str
    name: Optional[str] = None
    description: Optional[str] = None
    type: SchemaDataType
    required: Optional[bool] = None
    parent_id: Optional[str] = Field(default=None, alias="parentId")

idstrRequired

This is the unique identifier for the schema field. Use it as the parentId of nested fields.

Example: "<FIELD-ID>"

nameOptional[str]

This is the name of the schema field.

Example: "customerId"

descriptionOptional[str]

This is the description of the schema field.

Example: "The id of the customer to look up."

typeSchemaDataTypeRequired

requiredOptional[bool]

This indicates whether the field is required in the input.

Example: true

parent_idOptional[str]

This is the id of the parent field for nested structures, or null for a top-level field.

Tool

class Tool:
    id: Optional[str] = None
    name: str
    description: Optional[str] = None
    mode: ToolMode
    structured_schema: StructuredSchema = Field(alias="structuredSchema")

idOptional[str]

This is the id of the tool assigned by Confident AI.

Example: "<TOOL-ID>"

namestrRequired

This is the name of the tool.

Example: "get_customer_name"

descriptionOptional[str]

This is the description of the tool.

Example: "Looks up the customer's name by id."

modeToolModeRequired

structured_schemaStructuredSchemaRequired

ToolMode

This is the mode for your tool input fields, which controls whether fields outside the schema are allowed.

class ToolMode(Enum):
    ALLOW_ADDITIONAL = "ALLOW_ADDITIONAL"
    NO_ADDITIONAL = "NO_ADDITIONAL"
    STRICT = "STRICT"

ALLOW_ADDITIONAL · NO_ADDITIONAL · STRICT

Verbosity

This is the verbosity level for model output.

class Verbosity(Enum):
    LOW = "LOW"
    MEDIUM = "MEDIUM"
    HIGH = "HIGH"

LOW · MEDIUM · HIGH

Building a production pipeline?Design a scalable API workflow for evals, datasets, traces, and promptsTalk to an engineer

Last updated on

Built byConfident AI