---
title: PromptFactory
seo:
  title: PromptFactory — Python SDK
  description: Create, retrieve, tag, and list versioned prompt templates. (Python SDK)
description: Create, retrieve, tag, and list versioned prompt templates.
---

Access this via `client.prompts` -- you don't instantiate it directly.

```python
# 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\_\_()

```python
def __init__(client, project_id, project_name):
```

### Parameters

| Prop | Type | Default | Description |
| - | - | - | - |
| `client` | `JudgmentSyncClient` | - | |
| `project_id` | `Optional[str]` | - | |
| `project_name` | `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`).

```python
prompt = client.prompts.create(
    name="system-prompt",
    prompt="You are a {{tone}} assistant for {{product}}.",
    tags=["v2"],
)
```

```python
def create(name, prompt, tags=None) -> typing.Optional:
```

### Parameters

| Prop | Type | Default | Description |
| - | - | - | - |
| `name` | `str` | - | Prompt name. |
| `prompt` | `str` | - | The template string. Use {{variable}} for placeholders. |
| `tags?` | `Optional[List[str]]` | `None` | Tags to attach to this version (e.g. ["staging"]). |

### 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.

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

# Pinned to production tag
prompt = client.prompts.get(name="system-prompt", tag="production")
```

```python
def get(/, *, name, commit_id=None, tag=None) -> typing.Optional:
```

### Parameters

| Prop | Type | Default | Description |
| - | - | - | - |
| `name` | `str` | - | Prompt name. |
| `commit_id?` | `Optional[str]` | `None` | Fetch a specific version by its commit ID. |
| `tag?` | `Optional[str]` | `None` | Fetch the version with this tag (e.g. "production"). |

### 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.

```python
client.prompts.tag(
    name="system-prompt",
    commit_id=prompt.commit_id,
    tags=["production"],
)
```

```python
def tag(name, commit_id, tags) -> typing.Optional:
```

### Parameters

| Prop | Type | Default | Description |
| - | - | - | - |
| `name` | `str` | - | Prompt name. |
| `commit_id` | `str` | - | The version to tag. |
| `tags` | `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.

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

### Parameters

| Prop | Type | Default | Description |
| - | - | - | - |
| `name` | `str` | - | Prompt name. |
| `tags` | `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.

```python
versions = client.prompts.list(name="system-prompt")
for v in versions:
    print(f"{v.commit_id} tags={v.tags}")
```

```python
def list(name) -> typing.Optional:
```

### Parameters

| Prop | Type | Default | Description |
| - | - | - | - |
| `name` | `str` | - | Prompt name. |

### Returns

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