Skip to main content

Prompt operations

Prompt operations are the guard rails around the prompts your applications use. They make sure a prompt change reaches customers only after it was tested, show exactly what changed between two versions, let many prompts share one block of text, tell the right people when something changes, and keep a copy of every prompt in your Git repository. This page is for prompt owners, team leads and the admins who run the gateway. It builds on prompt versions, which explains environments and versions.

A real-world scenario​

A support team keeps its support-reply prompt in three environments. A writer improves the greeting in development, the team lead promotes it to staging, and the change sits there while the eval suite runs against staging version 3. The eval passes its quality gate, so the lead promotes staging version 3 to production with that eval run's id. The gateway checks that the run really tested staging version 3 and that it passed, copies the version into production with the house style partial written into its text, writes an audit row and posts in the team's Slack channel. A week later someone saves a change straight to production by mistake. The gateway refuses it, because production is protected. The prompt files also live in a GitLab repository, so the change history is reviewed there too.

Protected environments​

A protected environment only takes versions that were tested somewhere else and then promoted. Saving, patching or deleting a prompt there directly is refused with a 409 that says how to promote instead. production is protected from the start.

What it is for. Nobody can change what customers see by accident, from the Prompt Studio, the API or a script.

When it is on. Only Promote and POST /prompts/{prompt_id}/promote add versions there, and deleting a prompt that has a version there is refused.

When it is off. Admins can save to that environment directly, as before.

Default and who changes it. production is protected. A proxy admin changes it. Admin viewers can see the setting.

  1. In the Admin UI open Prompts, then the Protection and alerts tab.
  2. Tick the environments to protect under Protected environments.
  3. Leave Require a passed eval to promote on unless your team promotes without evals.
  4. Click Save settings.

Over the API:

curl -X PUT http://localhost:4000/prompts/ops/settings \
-H "Authorization: Bearer $SPANWAY_API_KEY" -H "Content-Type: application/json" \
-d '{"protected_environments": ["production"], "require_eval_verdict": true,
"alert_emails": ["prompt-owners@example.com"], "email_on": ["promoted", "deleted"]}'

Expected result: the settings as saved, with updated_by and updated_at. GET /prompts/ops/settings reads them. Every save writes an audit row with the settings before and after.

SettingWhat it doesDefault
protected_environmentsEnvironments that only take promoted versions.["production"]
require_eval_verdictWhen on, promoting into a protected environment needs a passed eval run of that exact version. When off, any admin can promote without one. Needs an Enterprise license with evals while on.true
alert_emailsWho is emailed when a prompt changes. Empty sends no email.empty
email_onWhich changes send that email: promoted, deleted, created, updated.["promoted", "deleted"]

Promote a tested version​

Promotion copies one version, unchanged, into another environment as that environment's next version. Into a protected environment it is the only way in.

  1. Run an eval of the version you want to promote. In the Admin UI open Evals, start a run on your dataset and pick the prompt, its version and its environment, or start it from CI. Give the run a quality gate, for example a minimum pass rate, so it can pass or fail. See evals.
  2. Open Prompts, click the prompt, then click Promote.
  3. Pick From environment (for example staging), leave Version empty for the newest or type a number, pick To environment (production), paste the Eval run id and add a Note if you like.
  4. Click Promote.

Over the API:

curl -X POST http://localhost:4000/prompts/support-reply/promote \
-H "Authorization: Bearer $SPANWAY_API_KEY" -H "Content-Type: application/json" \
-d '{"from_environment": "staging", "version": 3, "to_environment": "production",
"eval_run_id": "run_8f2c1a", "note": "Shorter greeting, passed the support eval"}'

Expected result: a 200 with the new production version under prompt and a promotion record: where it came from, the eval run, gate passed (or not_required when no eval was needed), the partial versions it wrote into the text under pinned_partials and who promoted it. The prompt's page shows the line "Promoted from staging v3 after eval run run_8f2c1a passed". Requests that ask for production get the new version on their next call.

The gateway refuses the promotion when the run is missing, tested another prompt, version or environment, or did not pass. A run passes when its quality gate has at least one check that passed and none that failed, the same verdict a CI job reads from GET /eval/runs/{run_id}/verdict. A run without a gate is neutral and does not count. The gateway also refuses the promotion when a partial the text uses, directly or inside another partial, got a new version after the eval run started, because the run never tested that text. Run the eval again and promote with the new run. Promoting into an environment that is not protected needs no eval, but when you send eval_run_id it is still checked.

Compare versions​

Compare shows what changed between any two versions: the template text as a diff and every setting that differs, such as the model or temperature.

  1. Open Prompts, click the prompt, then click Compare.
  2. Pick the left side (usually production) and the right side (usually the version you want to promote). Leave a version empty for the newest.
  3. Click Compare. Removed lines are red, added lines green, and changed settings are listed in a table.

Over the API:

curl "http://localhost:4000/prompts/support-reply/diff?from_environment=production&to_environment=staging" \
-H "Authorization: Bearer $SPANWAY_API_KEY"

Expected result: template_changed, a unified template_diff (lines starting with - were removed, + were added) and settings_changed, for example [{"field": "metadata.temperature", "before": 0.7, "after": 0.3}]. To see what one edit changed, compare two versions of one environment: ?from_environment=development&from_version=2&to_version=3. Reading changes nothing. Proxy admins and admin viewers.

Reusable partials​

A partial is a block of text many prompts share, such as your house style, a safety notice or a legal line. You write it once and include it in any dotprompt template with {{> name}}. {{> name@2}} pins version 2.

How it behaves. Saving a partial adds a new version. Prompts in development and staging that use {{> name}} get the new text on their next request. When a version is promoted into a protected environment, every partial in it, including partials inside other partials, is written out into the stored text, and the versions used are listed in the promotion record. Production therefore keeps rendering the exact text it was tested with until you promote again, and saving or deleting a partial later cannot change it. A partial can include other partials up to five levels deep, and a partial that includes itself is refused. A partial that any stored prompt version or any other partial still includes cannot be deleted, so deleting a nested partial cannot break the prompts that reach it through another partial. Partials in config.yaml prompts are not checked before a delete.

  1. Open Prompts, then the Partials tab.
  2. Under Save a partial enter a Name such as tone, the Text and an optional Description, then click Save partial.
  3. Add {{> tone}} to a prompt in the Prompt Studio and save it in development.

Over the API:

curl -X POST http://localhost:4000/prompts/ops/partials \
-H "Authorization: Bearer $SPANWAY_API_KEY" -H "Content-Type: application/json" \
-d '{"name": "tone", "content": "Answer in a warm, plain tone. Never promise refunds.", "description": "House style"}'

Expected result: the saved partial with version 1, or the next number when the name exists. GET /prompts/ops/partials lists every partial with its newest version, GET /prompts/ops/partials/tone returns every version, and DELETE /prompts/ops/partials/tone removes them all. Each gateway loads partials from the database with the rest of its prompts, so another gateway instance picks up a change within its usual refresh.

Change alerts​

Prompt changes go to the alert channels you already use, such as Slack, Microsoft Teams or a webhook, as four alert types, and to an email list.

Alert typeSent whenOn by default
prompt_promotedA version was promoted, with the eval run that allowed it.yes
prompt_deletedA prompt was deleted from one environment or from all.yes
prompt_createdA new prompt was saved, including one pulled from Git.no
prompt_updatedA prompt got a new version.no
  1. Set up an alert destination on Logging and Alerts, see alerting. Tick Prompt Created or Prompt Updated there if you want those too.
  2. For email, configure an email provider, then on Prompts, Protection and alerts, list the addresses under Email these people about prompt changes and pick the changes under Send that email when a prompt is.

Expected result: after a promotion, Slack shows a message such as Prompt support-reply version 2 was promoted in production by admin@example.com (from staging version 3, eval run run_8f2c1a passed). Alerts and emails name the prompt, the environment, the version and who changed it, never the prompt text.

Sync with a Git repository​

Keep prompts in a GitLab (gitlab.com or self-managed) or Bitbucket Cloud repository as .prompt files, one file per prompt, named after the prompt id: prompts/support-reply.prompt. Pull copies changed files into an environment as new versions. Push writes an environment's prompts back as one commit, so you get review and history in your usual Git tools.

What it protects. Pulled prompts can only be saved in an environment that is not protected, so a change made in the repository still goes through an eval and a promotion before customers see it.

  1. Create a project or repository access token that may read and write the repository.
  2. Open Prompts, then the Git sync tab. Under Connect a repository fill in Name, Provider, Repository (group/project or workspace/repository), Branch and folder, Save pulled prompts in (development), Self-managed GitLab address only for your own GitLab, and Access token. Click Connect repository.
  3. Click Pull to import, or Push to export the connection's environment.

Over the API:

curl -X POST http://localhost:4000/prompts/ops/git_syncs \
-H "Authorization: Bearer $SPANWAY_API_KEY" -H "Content-Type: application/json" \
-d '{"name": "support-prompts", "provider": "gitlab", "repository": "acme/support-prompts",
"branch": "main", "path": "prompts", "environment": "development", "access_token": "'"$GITLAB_TOKEN"'"}'

curl -X POST http://localhost:4000/prompts/ops/git_syncs/$SYNC_ID/pull -H "Authorization: Bearer $SPANWAY_API_KEY"

curl -X POST http://localhost:4000/prompts/ops/git_syncs/$SYNC_ID/push \
-H "Authorization: Bearer $SPANWAY_API_KEY" -H "Content-Type: application/json" -d '{"environment": "production"}'

Expected result: the connection without its token (access_token_set: true). A pull answers with the prompts it created, updated and left unchanged, and skipped files with a reason. A push answers with the new commit and the files it written, or no commit when nothing changed.

How it works. The token is stored encrypted and never returned. A pull reads at most 200 files of at most 256 KiB each. A file whose name is not a valid prompt id (letters, digits, - and _), a second file with the same id in a subfolder, a prompt stored with another integration and a file that is not a valid dotprompt template, such as one with broken YAML front matter, are skipped and listed with the reason, and the other files are still imported. A push writes only prompts stored as dotprompt text and leaves files that already match. The gateway follows no redirects from the repository host, and a self-managed GitLab address on a private network is refused unless its host is in user_url_allowed_hosts. The address is checked again before every request and the request goes to the address that passed the check, so a host name that later resolves to a private network never receives the token.

Audit​

Every change on this page writes an audit row, see audit logs.

ChangeTableActionWhat the row holds
PromotionSpanway_PromptTableupdatedThe target's newest version before, the new version after with operation promote and the promotion record. Templates are replaced by their hash.
SettingsSpanway_PromptOpsSettingsupdatedThe settings before and after.
Partial saved or deletedSpanway_PromptPartialTablecreated, updated, deletedName, version and description, with the text replaced by its hash.
Git connectionSpanway_PromptGitSyncTablecreated, deletedProvider, repository, branch, folder and environment, never the token.
Git pullSpanway_PromptTablecreated, updatedOne row per saved prompt, with source git_sync:<name> and the file path.
Git pushSpanway_PromptGitSyncTableexportedThe environment, the commit and the files written.

{{ops:^/prompts/ops/|^/prompts/{prompt_id}/promote$|^/prompts/{prompt_id}/diff$}}

Errors​

Status and messageWhereMeaningFix
409 The production environment is protected. Save the change in another environment and promote it with POST /prompts/<id>/promote, ...POST, PUT, PATCH and DELETE on /prompts, Update and Delete PromptThe change went straight to a protected environment.Save in development or staging, then promote.
400 Promoting into production needs a passed eval run of <id> <env> version <n>. ...PromoteNo eval_run_id was sent.Run an eval of that version and send its id.
409 Eval run <run> tested <what>, not <id> <env> version <n>PromoteThe run tested something else.Run an eval of the version you are promoting.
409 Eval run <run> did not pass its quality gate: the verdict is failedPromoteThe run failed, or is neutral (no gate), pending or error.Fix the prompt or give the run a gate, then run it again.
403 The 'evals' feature needs a Spanway enterprise license that includes it.PromoteThe eval check needs evals in the licence.Add evals, or turn off Require a passed eval to promote.
404 Prompt <id> has no version <n> in <env>, Eval run <run> not foundPromote, CompareThe version or run does not exist.Check the ids.
400 from_environment and to_environment must differ, Cannot promote config prompts.PromoteSame environment on both sides, or a config.yaml prompt.Pick two environments, or change the file.
400 Cannot promote: Unknown partial <name>PromoteThe text includes a partial that no longer exists.Save the partial again or remove the include.
409 Cannot promote: partial <name> version <n> was saved after eval run <run> started, so the run did not test it. ...PromoteA partial the text uses changed after the eval run started.Run the eval again and promote with the new run.
409 Partial <name> is still used by <prompt> (<env>), partial <other>. Remove it from those prompts and partials first.Delete partialA stored prompt version or another partial still includes it.Remove the include from those prompts and partials.
400 Pulled prompts cannot be saved in <env> because it is protected. ...Connect repositoryThe chosen environment is protected.Pick development or staging.
409 A repository connection named <name> already existsConnect repositoryNames are unique.Pick another name.
400 The GitLab address is not allowed: ...Connect repository, Pull, PushThe address points at a private network.Use the public address, or allow the host with user_url_allowed_hosts.
502 GitLab answered 401 Unauthorized and similarPull, PushThe repository host refused or failed the call. The reason is kept as Last error.Check the token, the repository path and the branch.
403 Only proxy admins can ...Every writeThe key is not a proxy admin. Admin viewers can read.Use an admin key.

All errors are listed in the error reference.

Logs​

LevelLineMeaning
INFOprompt operations settings changed by <user>: protected=<environments> require_eval_verdict=<true or false>The settings were saved.
INFOprompt git sync <name> pulled into <environment>: <n> created, <n> updated, <n> skippedA pull finished.
INFOprompt partial <name> deleted by <user> (<n> versions)A partial was deleted.
INFOprompt change email for <id> not sent: no email callback is configuredEmails are listed but no email provider is set up.
ERRORprompt change alert failed for <id>: <error>, prompt change email failed for <id>: <error>The change was saved but its alert or email failed.
WARNINGprompt partials sync failed, keeping the loaded partials: <error>This gateway could not reload partials and keeps the ones it has.

See the log reference.