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
clientJudgmentSyncClient
JudgmentSyncClientproject_idOptional[str]
Optional[str]project_namestr
strcreate()
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
namestr
Prompt name.
strpromptstr
The template string. Use {{variable}} for placeholders.
strtags?Optional[List[str]]
Tags to attach to this version (e.g. ["staging"]).
Optional[List[str]]NoneReturns
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
namestr
Prompt name.
strcommit_id?Optional[str]
Fetch a specific version by its commit ID.
Optional[str]Nonetag?Optional[str]
Fetch the version with this tag (e.g. "production").
Optional[str]NoneReturns
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
namestr
Prompt name.
strcommit_idstr
The version to tag.
strtagsList[str]
Tags to attach (e.g. ["production"]).
List[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
namestr
Prompt name.
strtagsList[str]
Tags to remove.
List[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
namestr
Prompt name.
strReturns
typing.Optional - All Prompt versions, or None on failure.