Skip to main content
Glama

prompt_optimize

Rewrite a prompt using an LLM and failing eval scenarios, then review the proposed content, diff, and validation issues or save it as a new prompt version.

Instructions

LLM-assisted prompt rewrite from a failing eval run — the portal's /admin/prompts/{id}/optimize, non-streaming. Same helpers: the failing scenarios of run_id and the prompt's newest version go into build_optimizer_meta_prompt, and model_id writes the rewrite.

Returns {proposal: {content, chars}, diff_stat (vs the current newest
version), validation: {problems}, failing_scenarios}. With
confirm=true the proposal is saved IN-PROCESS as version N+1 (so a
half-Arabic body never round-trips through the client) after the same
validation gate create_version uses; it is NOT served until you pin it
(prompts action=serve). Takes as long as one LLM call.

Tool call template

Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.

{
  "id": 1,
  "jsonrpc": "2.0",
  "method": "tools/call",
  "params": {
    "arguments": {
      "prompt_id": "<prompt_id>",
      "run_id": "<run_id>",
      "model_id": "<model_id>"
    },
    "name": "prompt_optimize"
  }
}

Input Schema

NameRequiredDescriptionDefault
envNoConfig branch: which `environment` rows of the AI config DB to read/write. staging = the editable working set (default); prod = what production serves.staging
notesNoNotes for the saved version.
run_idYesEval run whose FAILING scenarios drive the rewrite.
confirmNofalse (default) = return the proposal only. true = also save it as a NEW prompt version (not served; pin it with prompts action=serve).
model_idYesagent_models row (a chat model) that writes the rewrite.
prompt_idYesPrompt slot to rewrite (its NEWEST version is the input).
include_contentNoReturn the proposed prompt text (default true).
override_validationNoSave even if the proposal fails prompt validation (needs confirm=true; audited).

Output Schema

NameRequiredDescriptionDefault
resultYes

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observedv0.1.0

TDQS

A4.6/5.0
Behavior5/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations, the description carries the full burden and does so well: non-streaming, in-process save so a non-ASCII body never round-trips through the client, the same validation gate as `create_version`, not served until pinned, and an audited `override_validation` path. It even discloses latency ('takes as long as one LLM call'), which is exactly the kind of cost signal an agent needs before invoking.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Front-loaded with the core purpose, then returns, then the confirm/pin semantics, which is the right ordering. Slightly dense with parenthetical route paths and rationale clauses, but nearly every clause carries information an agent would otherwise have to guess.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness5/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For an 8-parameter mutation tool with LLM cost and a multi-step pin workflow, the description covers inputs, outputs, side effects, validation, and follow-up actions. An output schema exists, yet the inline return summary is harmless reinforcement rather than padding.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema coverage is 100%, so the baseline is 3, but the description adds real meaning: `run_id` supplies the *failing* scenarios, `prompt_id` uses the prompt's *newest* version as input, and `confirm=true` saves as version N+1. It reinforces rather than merely restates the schema's parameter documentation.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

States a specific verb and resource: an LLM-assisted prompt rewrite driven by the failing scenarios of an eval run, and names the underlying portal route. It also distinguishes itself from adjacent operations by naming `create_version` and `prompts action=serve`, so an agent can tell it apart from plain version creation.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

Gives clear operational context: default behavior returns a proposal only, and `confirm=true` saves it as a new version which must then be pinned via `prompts action=serve`. It explains the prerequisite chain for going live but does not explicitly state when to prefer this over other prompt-editing paths beyond that pinning note.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.