# Get Prompt Template

> Hydrates a managed prompt template with dynamic variables.

Source: https://docs.sommatic.ai/en/nodes/ai.prompt/

- Slug: `ai.prompt`
- Family: AI
- Version: 1.0.0
- Status: Partial. On success the worker returns no port, so the engine follows `out`, which this node does not declare: an edge drawn from its success port never fires. Until it is fixed, do not chain nodes after its success path.
- Execution: sync

Hydrates a managed prompt template with dynamic variables.

Instead of hardcoding prompts in your workflow, use this operator to fetch versioned, managed templates from the Prompt Registry and fill them with workflow data.

**Benefits:**
- **Separation of Concerns:** Prompts can be tuned by Prompt Engineers without changing code.
- **Version Control:** Use specific versions of a prompt.
- **Reusability:** Share standard system prompts across workflows.

## Configuration

- `template_id` (string, required): ID of the managed prompt template.
- `version` (string, optional): Specific version tag or "latest". Default: `latest`.

Its configuration shows the shared execution settings, but this node does not apply retries (`retryOnFail`, `maxTries`) yet. `continueOnFail` is not applied by any node.

## Output ports

- `success` (default): Success
- `error`: Error

## Input contract

- `variables` (object, required): Key-value pairs to inject into the template placeholders.

## Output contract

- `prompt` (string, optional): The fully hydrated prompt string.
- `config` (object, optional): Model configuration associated with the prompt.

## In expressions

What a later node can read from this node's output with `$("Get Prompt Template").item.json.<path>` (write your node's label instead of `Get Prompt Template`). **Editor** marks the paths the workflow editor suggests under Previous Nodes (the output contract); **Worker** marks the paths the worker really returns through `success`, from the output shown in Ports.

- `$("Get Prompt Template").item.json.prompt` (string) = `"Summarize the complaint from Ana Ruiz in two…"`: The fully hydrated prompt string.
- `$("Get Prompt Template").item.json.config` (object) = `{…}`: Model configuration associated with the prompt.
- `$("Get Prompt Template").item.json.config.provider` (string) = `"azure-openai"` (Not suggested by the editor)
- `$("Get Prompt Template").item.json.config.model` (string) = `"gpt-4o-mini"` (Not suggested by the editor)
- `$("Get Prompt Template").item.json.config.language` (string) = `"en"` (Not suggested by the editor)
- `$("Get Prompt Template").item.json.config.format` (string) = `"text"` (Not suggested by the editor)


## How it works

Loads a managed prompt template from the backend, replaces its `{{ key }}` placeholders with `variables`, and returns the prompt plus the provider and model of the template. It does not call any LLM.

1. Resolves the node config: expressions in config keys are evaluated against the run; the incoming item is used as-is.
2. Merges the incoming item with the resolved config and requires `template_id`.
3. Fetches the template record from the backend prompt registry and takes its body from `template_body`, `content` or `template`, in that order.
4. Replaces every `{{ key }}` (spaces optional) with the value of `variables.key`. Placeholders without a variable stay as they are.
5. If the template has an `llm_provider_id`, reads that provider record to fill `config.provider` (its slug) and `config.model` (deployment name or default model); a failure here only logs and leaves them `null`.
6. Returns `{ prompt, config }` without a port, so the engine routes it to `out`.

## In a workflow

### Node

```json
{
  "node_id": "node-load-prompt",
  "label": "Load complaint prompt",
  "operator_slug": "ai.prompt",
  "operator_version": "1.0.0",
  "config": {
    "template_id": "<prompt_template_id>",
    "version": "latest"
  }
}
```

### Envelope

```json
{
  "ok": true,
  "port": "out",
  "data": {
    "prompt": "Summarize the complaint from Ana Ruiz in two sentences.",
    "config": {
      "provider": "azure-openai",
      "model": "gpt-4o-mini",
      "language": "en",
      "format": "text"
    }
  }
}
```

## Output ports (behaviour in the code)

### `success`

Never fires. On success the worker returns no port, the engine uses `out`, and `out` is not declared by this node: edges drawn from `success` do not run, so the workflow stops here.

```json
{
  "prompt": "Summarize the complaint from Ana Ruiz in two sentences.",
  "config": {
    "provider": "azure-openai",
    "model": "gpt-4o-mini",
    "language": "en",
    "format": "text"
  }
}
```

### `error`

Validation or a backend call failed. `data` is `{ error }`, plus `response` with the backend body when the HTTP call failed.

```json
{
  "error": "Prompt Template <template_id> not found"
}
```

## Behaviour in the code

- `version`: Declared but ignored: the current record of the template is always used.
- `variables`: Read from the incoming item; a `variables` key in the config (undeclared, may be an expression) overrides it. Values are inserted as strings, so objects become `[object Object]`. Keys are used inside a regular expression without escaping, so use plain names (letters, digits, `_`).

## Errors

| Message | Port | Cause and fix |
| --- | --- | --- |
| `Missing 'template_id'` | `error` | `template_id` is empty. |
| `Prompt Template <template_id> not found` | `error` | The registry has no template with that id. |
| `Template <template_id> has no content` | `error` | The template record has no body. |
| `Request failed with status code <status>` | `error` | The backend answered the template lookup with a non-2xx status. |

## Notes and limits

- This node is partial: until the success port is fixed, do not connect nodes after it. Use the template body directly in an `ai.*` node instead.
- Backend requests have no timeout set.
- The engine does not apply `execution.retryOnFail`, `maxTries`, `waitBetweenTries` or `continueOnFail` to this node. Handle failures by wiring the `error` port.


## Contracts (JSON Schema)

### All (`*.definition.js`)

```json
{
  "slug": "ai.prompt",
  "name": "Get Prompt Template",
  "category": "ai",
  "version": "1.0.0",
  "description": "Hydrates a managed prompt template with dynamic variables.\n\n  Instead of hardcoding prompts in your workflow, use this operator to fetch versioned, managed templates from the Prompt Registry and fill them with workflow data.\n\n  **Benefits:**\n  - **Separation of Concerns:** Prompts can be tuned by Prompt Engineers without changing code.\n  - **Version Control:** Use specific versions of a prompt.\n  - **Reusability:** Share standard system prompts across workflows.",
  "capabilities": [
    "prompt-engineering",
    "template",
    "ai"
  ],
  "config_schema": {
    "type": "object",
    "required": [
      "template_id"
    ],
    "properties": {
      "template_id": {
        "type": "string",
        "title": "Template ID",
        "description": "ID of the managed prompt template.",
        "ui_widget": "prompt_picker"
      },
      "version": {
        "type": "string",
        "title": "Version",
        "default": "latest",
        "description": "Specific version tag or \"latest\"."
      },
      "execution": {
        "type": "object",
        "title": "Execution Settings",
        "properties": {
          "alwaysOutputData": {
            "type": "boolean",
            "title": "Always Output Data",
            "description": "Always output data, even on error (if configured).",
            "default": false
          },
          "retryOnFail": {
            "type": "boolean",
            "title": "Retry On Fail",
            "description": "Retry the execution if it fails.",
            "default": false
          },
          "maxTries": {
            "type": "integer",
            "title": "Max Retries",
            "description": "Number of retries.",
            "default": 3,
            "displayOptions": {
              "show": {
                "retryOnFail": [
                  true
                ]
              }
            }
          },
          "waitBetweenTries": {
            "type": "integer",
            "title": "Wait Between Retries (ms)",
            "default": 1000,
            "displayOptions": {
              "show": {
                "retryOnFail": [
                  true
                ]
              }
            }
          },
          "continueOnFail": {
            "type": "boolean",
            "title": "Continue On Fail",
            "description": "Do not crash workflow on error.",
            "default": false
          },
          "timeout_ms": {
            "type": "integer",
            "title": "Timeout (ms)",
            "description": "Max execution time for this node before it is killed, in milliseconds. Honored by long-running operators (e.g. OCR/extraction, inline code). Default 300000 (5 min).",
            "default": 300000
          }
        }
      }
    }
  },
  "input_contract_schema": {
    "type": "object",
    "properties": {
      "variables": {
        "type": "object",
        "description": "Key-value pairs to inject into the template placeholders."
      }
    },
    "required": [
      "variables"
    ]
  },
  "output_contract_schema": {
    "type": "object",
    "properties": {
      "prompt": {
        "type": "string",
        "description": "The fully hydrated prompt string."
      },
      "config": {
        "type": "object",
        "description": "Model configuration associated with the prompt."
      }
    }
  },
  "ports": [
    {
      "port_id": "success",
      "label": "Success",
      "is_default": true
    },
    {
      "port_id": "error",
      "label": "Error"
    }
  ],
  "execution_mode": "sync",
  "tags": [
    "prompt",
    "template",
    "registry"
  ],
  "is_stateful": false,
  "publisher": {
    "identity": "org_sommatic_ai",
    "profile": {
      "name": "Sommatic AI",
      "verified": true,
      "url": "https://me.veripass.com/sommatic",
      "logo_url": null
    }
  }
}
```

### config_schema

```json
{
  "type": "object",
  "required": [
    "template_id"
  ],
  "properties": {
    "template_id": {
      "type": "string",
      "title": "Template ID",
      "description": "ID of the managed prompt template.",
      "ui_widget": "prompt_picker"
    },
    "version": {
      "type": "string",
      "title": "Version",
      "default": "latest",
      "description": "Specific version tag or \"latest\"."
    },
    "execution": {
      "type": "object",
      "title": "Execution Settings",
      "properties": {
        "alwaysOutputData": {
          "type": "boolean",
          "title": "Always Output Data",
          "description": "Always output data, even on error (if configured).",
          "default": false
        },
        "retryOnFail": {
          "type": "boolean",
          "title": "Retry On Fail",
          "description": "Retry the execution if it fails.",
          "default": false
        },
        "maxTries": {
          "type": "integer",
          "title": "Max Retries",
          "description": "Number of retries.",
          "default": 3,
          "displayOptions": {
            "show": {
              "retryOnFail": [
                true
              ]
            }
          }
        },
        "waitBetweenTries": {
          "type": "integer",
          "title": "Wait Between Retries (ms)",
          "default": 1000,
          "displayOptions": {
            "show": {
              "retryOnFail": [
                true
              ]
            }
          }
        },
        "continueOnFail": {
          "type": "boolean",
          "title": "Continue On Fail",
          "description": "Do not crash workflow on error.",
          "default": false
        },
        "timeout_ms": {
          "type": "integer",
          "title": "Timeout (ms)",
          "description": "Max execution time for this node before it is killed, in milliseconds. Honored by long-running operators (e.g. OCR/extraction, inline code). Default 300000 (5 min).",
          "default": 300000
        }
      }
    }
  }
}
```

### input_contract_schema

```json
{
  "type": "object",
  "properties": {
    "variables": {
      "type": "object",
      "description": "Key-value pairs to inject into the template placeholders."
    }
  },
  "required": [
    "variables"
  ]
}
```

### output_contract_schema

```json
{
  "type": "object",
  "properties": {
    "prompt": {
      "type": "string",
      "description": "The fully hydrated prompt string."
    },
    "config": {
      "type": "object",
      "description": "Model configuration associated with the prompt."
    }
  }
}
```

### ports

```json
[
  {
    "port_id": "success",
    "label": "Success",
    "is_default": true
  },
  {
    "port_id": "error",
    "label": "Error"
  }
]
```
