Skip to content
Judgment Labs
Esc
↑↓navigate↵open⌘Jpreview
On this page

PromptFactory

Create, retrieve, tag, and list versioned prompt templates.

Access this via client.prompts – you don’t instantiate it directly.

# Create a new prompt
prompt = client.prompts.create(
    name="system-prompt",
    prompt="You are a {{tone}} assistant for {{product}}.",
    tags=["v1"],
)

# Retrieve by tag
prompt = client.prompts.get(name="system-prompt", tag="production")

# Compile with variables
text = prompt.compile(tone="helpful", product="Acme Search")

__init__()

def __init__(client, project_id, project_name):

Parameters

PropType
clientJudgmentSyncClient
TypeJudgmentSyncClient
project_idOptional[str]
TypeOptional[str]
project_namestr
Typestr

create()

Create a new prompt version.

If a prompt with this name already exists, a new version is created automatically (linked via parent_commit_id).

prompt = client.prompts.create(
    name="system-prompt",
    prompt="You are a {{tone}} assistant for {{product}}.",
    tags=["v2"],
)
def create(name, prompt, tags=None) -> typing.Optional:

Parameters

PropType
namestr

Prompt name.

Typestr
promptstr

The template string. Use {{variable}} for placeholders.

Typestr
tags?Optional[List[str]]

Tags to attach to this version (e.g. ["staging"]).

TypeOptional[List[str]]
DefaultNone

Returns

typing.Optional - The created Prompt, or None if the project is not resolved.


get()

Retrieve a prompt by name.

By default returns the latest version. Pass tag or commit_id to pin to a specific version.

# Latest version
prompt = client.prompts.get(name="system-prompt")

# Pinned to production tag
prompt = client.prompts.get(name="system-prompt", tag="production")
def get(/, *, name, commit_id=None, tag=None) -> typing.Optional:

Parameters

PropType
namestr

Prompt name.

Typestr
commit_id?Optional[str]

Fetch a specific version by its commit ID.

TypeOptional[str]
DefaultNone
tag?Optional[str]

Fetch the version with this tag (e.g. "production").

TypeOptional[str]
DefaultNone

Returns

typing.Optional - The Prompt, or None if not found.


tag()

Tag a specific prompt version.

Use tags to mark versions for deployment (e.g. "production", "staging") so you can retrieve them by tag later.

client.prompts.tag(
    name="system-prompt",
    commit_id=prompt.commit_id,
    tags=["production"],
)
def tag(name, commit_id, tags) -> typing.Optional:

Parameters

PropType
namestr

Prompt name.

Typestr
commit_idstr

The version to tag.

Typestr
tagsList[str]

Tags to attach (e.g. ["production"]).

TypeList[str]

Returns

typing.Optional - The commit ID of the tagged version, or None on failure.


untag()

Remove tags from a prompt.

def untag(name, tags) -> typing.Optional:

Parameters

PropType
namestr

Prompt name.

Typestr
tagsList[str]

Tags to remove.

TypeList[str]

Returns

typing.Optional - Commit IDs of the versions that were untagged, or None on failure.


list()

List all versions of a prompt.

Returns versions in reverse chronological order.

versions = client.prompts.list(name="system-prompt")
for v in versions:
    print(f"{v.commit_id} tags={v.tags}")
def list(name) -> typing.Optional:

Parameters

PropType
namestr

Prompt name.

Typestr

Returns

typing.Optional - All Prompt versions, or None on failure.

Was this page helpful?