PromptFactory
Create, retrieve, tag, and list versioned prompt templates.
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
client
required:JudgmentSyncClient
project_id
required:Optional[str]
project_name
required:str
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
name
required:str
Prompt name.
prompt
required:str
The template string. Use {{variable}} for placeholders.
tags
:Optional[List[str]]
Tags to attach to this version (e.g. ["staging"]).
None
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
name
required:str
Prompt name.
commit_id
:Optional[str]
Fetch a specific version by its commit ID.
None
tag
:Optional[str]
Fetch the version with this tag (e.g. "production").
None
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
name
required:str
Prompt name.
commit_id
required:str
The version to tag.
tags
required:List[str]
Tags to attach (e.g. ["production"]).
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
name
required:str
Prompt name.
tags
required:List[str]
Tags to remove.
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
name
required:str
Prompt name.
Returns
typing.Optional - All Prompt versions, or None on failure.