MCPInstall

arize-prompt-optimization

Optimizes, improves, and debugs LLM prompts using production trace data, evaluations, and annotations. Extracts prompts from spans, gathers performance signal, and runs a data-driven optimization loop using the ax CLI. Use when the user mentions optimize prompt, improve prompt, make AI respond better, improve output quality, prompt engineering, prompt tuning, or system prompt improvement.

Installs
3.3K
Last 24h
+16
Trending rank
#6773
Security
Not audited

Install

Works with every agent the skills CLI supports.

npx skills add https://github.com/arize-ai/arize-skills --skill arize-prompt-optimization
  1. 01

    Install

    Run the command in your project. The CLI asks which agents to install for.

  2. 02

    Describe the task

    Ask your agent for something this skill covers. It loads arize-prompt-optimization automatically when relevant.

  3. 03

    Review the result

    The agent follows the SKILL.md steps, scripts and references bundled with the skill.

SKILL.md

The instructions your agent reads when the skill is triggered.

Arize Prompt Optimization Skill

SPACE — --space flags accept a space name (e.g., my-workspace) or a base64 space ID (e.g., U3BhY2U6...). Confirm a known name with ax spaces get NAME; ax spaces list is for human browsing.

Related skills

  • arize-prompts: Create, version, and label prompts in Prompt Hub with ax prompts (JSON messages, providers, labels such as production). Use that skill when the artifact should live in Arize; use arize-prompt-optimization below to improve prompt text from traces, datasets, and experiments.

Concepts

Where Prompts Live in Trace Data

LLM applications emit spans following OpenInference semantic conventions. Prompts are stored in different span attributes depending on the span kind and instrumentation:

ColumnWhat it containsWhen to use
attributes.llm.input_messagesStructured chat messages (system, user, assistant, tool) in role-based formatPrimary source for chat-based LLM prompts
attributes.llm.input_messages.rolesArray of roles: system, user, assistant, toolExtract individual message roles
attributes.llm.input_messages.contentsArray of message content stringsExtract message text
attributes.input.valueSerialized prompt or user question (generic, all span kinds)Fallback when structured messages are not available
attributes.llm.prompt_template.templateTemplate with {variable} placeholders (e.g., "Answer {question} using {context}")When the app uses prompt templates
attributes.llm.prompt_template.variablesTemplate variable values (JSON object)See what values were substituted into the template
attributes.output.valueModel response textSee what the LLM produced
attributes.llm.output_messagesStructured model output (including tool calls)Inspect tool-calling responses

Finding Prompts by Span Kind

  • LLM span (attributes.openinference.span.kind = 'LLM'): Check attributes.llm.input_messages for structured chat messages, OR attributes.input.value for a serialized prompt. Check attributes.llm.prompt_template.template for the template.
  • Chain/Agent span: attributes.input.value contains the user's question. The actual LLM prompt lives on child LLM spans -- navigate down the trace tree.
  • Tool span: attributes.input.value has tool input, attributes.output.value has tool result. Not typically where prompts live.

Performance Signal Columns

These columns carry the feedback data used for optimization:

Column patternSourceWhat it tells you
annotation.<name>.labelHuman reviewersCategorical grade (e.g., correct, incorrect, partial)
annotation.<name>.scoreHuman reviewersNumeric quality score (e.g., 0.0 - 1.0)
annotation.<name>.textHuman reviewersFreeform explanation of the grade
eval.<name>.labelLLM-as-judge evalsAutomated categorical assessment
eval.<name>.scoreLLM-as-judge evalsAutomated numeric score
eval.<name>.explanationLLM-as-judge evalsWhy the eval gave that score -- most valuable for optimization
attributes.input.valueTrace dataWhat went into the LLM
attributes.output.valueTrace dataWhat the LLM produced
{experiment_name}.outputExperiment runsOutput from a specific experiment

Prerequisites

Proceed directly with the task — run the ax command you need. Do NOT check versions, env vars, or profiles upfront.

If an ax command fails, troubleshoot based on the error:

  • command not found or version error → see references/ax-setup.md
  • 401 Unauthorized / missing API key → run ax profiles show to inspect the current profile. If the profile is missing or the API key is wrong, follow references/ax-profiles.md to create/update it. If the user doesn't have their key, direct them to https://app.arize.com/admin > API Keys
  • Space unknown → see Space
  • Project unclear → ask the user, or run ax projects list -o json --limit 100 and present as selectable options
  • LLM provider call fails (missing provider credentials) → run ax ai-integrations list --space SPACE to check for platform-managed credentials. If none exist, use the arize-ai-provider-integration skill — never ask the user to paste a provider key into chat.
  • Security: Never read .env files or search the filesystem for credentials. Exception: the non-secret ARIZE_SPACE_ID line (see Space). Use ax profiles for Arize credentials and ax ai-integrations for LLM provider keys. Never ask the user to paste secrets into chat. For missing credentials, see references/ax-profiles.md.

When you must ask the user first

Still prefer ax lookups over open-ended questions: confirm a known name with ax projects get NAME --space SPACE or ax datasets get NAME --space SPACE (list is for human browsing). If you still cannot proceed (e.g. multiple projects match the name the user gave, unclear trace vs experiment path, or destructive scope), do not jump straight into questions — use the same explicit framing as arize-instrumentation when it stops for scope or confirmation:

  1. Acknowledge the skill, e.g.: I found the arize-prompt-optimization skill in this repo (you may add skills/arize-prompt-optimization/SKILL.md if helpful).
  2. Then a clear pause line, e.g.: A few clarifying questions before I invoke it:
  3. Ask minimal numbered or short bullet questions — only what blocks the next ax step in this skill.

Phase 1: Extract the Current Prompt

Find LLM spans containing prompts

# Sample LLM spans (where prompts live)
ax spans export PROJECT --space SPACE --filter "attributes.openinference.span.kind = 'LLM'" -l 10 --stdout

# Filter by model
ax spans export PROJECT --space SPACE --filter "attributes.llm.model_name = 'gpt-4o'" -l 10 --stdout

# Filter by span name (e.g., a specific LLM call)
ax spans export PROJECT --space SPACE --filter "name = 'ChatCompletion'" -l 10 --stdout

Export a trace to inspect prompt structure

# Export all spans in a trace
ax spans export PROJECT --space SPACE --trace-id TRACE_ID --stdout > spans.json

# Export a single span
ax spans export PROJECT --space SPACE --span-id SPAN_ID

Extract prompts from exported JSON

# Extract structured chat messages (system + user + assistant)
jq '.[0] | {
  messages: .attributes.llm.input_messages,
  model: .attributes.llm.model_name
}' spans.json

# Extract the system prompt specifically
jq '[.[] | select(.attributes.llm.input_messages.roles[]? == "system")] | .[0].attributes.llm.input_messages' spans.json

# Extract prompt template and variables
jq '.[0].attributes.llm.prompt_template' spans.json

# Extract from input.value (fallback for non-structured prompts)
jq '.[0].attributes.input.value' spans.json

Reconstruct the prompt as messages

Once you have the span data, reconstruct the prompt as a messages array:

[
  {"role": "SYSTEM", "content": "You are a helpful assistant that..."},
  {"role": "USER", "content": "Given {input}, answer the question: {question}"}
]

If the span has attributes.llm.prompt_template.template, the prompt uses variables. Preserve these placeholders ({variable} or {{variable}}) -- they are substituted at runtime.

Phase 2: Gather Performance Data

From traces (production feedback)

# Find error spans -- these indicate prompt failures
ax spans export PROJECT --space SPACE \
  --filter "status_code = 'ERROR' AND attributes.openinference.span.kind = 'LLM'" \
  -l 20 --stdout

# Find spans with low eval scores
ax spans export PROJECT --space SPACE \
  --filter "annotation.correctness.label = 'incorrect'" \
  -l 20 --stdout

# Find spans with high latency (may indicate overly complex prompts)
ax spans export PROJECT --space SPACE \
  --filter "attributes.openinference.span.kind = 'LLM' AND latency_ms > 10000" \
  -l 20 --stdout

# Export error traces for detailed inspection
ax spans export PROJECT --space SPACE --trace-id TRACE_ID

From datasets and experiments

# Export a dataset (ground truth examples)
ax datasets export DATASET_NAME --space SPACE
# -> dataset_*/examples.json

# Export experiment results (what the LLM produced)
ax experiments export EXPERIMENT_NAME --dataset DATASET_NAME --space SPACE
# -> experiment_*/runs.json

Merge dataset + experiment for analysis

Join the two files by example_id to see inputs alongside outputs and evaluations:

# Count examples and runs
jq 'length' dataset_*/examples.json
jq 'length' experiment_*/runs.json

# View a single joined record
jq -s '
  .[0] as $dataset |
  .[1][0] as $run |
  ($dataset[] | select(.id == $run.example_id)) as $example |
  {
    input: $example,
    output: $run.output,
    evaluations: $run.evaluations
  }
' dataset_*/examples.json experiment_*/runs.json

# Find failed examples (where eval score < threshold)
jq '[.[] | select(.evaluations.correctness.score < 0.5)]' experiment_*/runs.json

Identify what to optimize

Look for patterns across failures:

  1. Compare outputs to ground truth: Where does the LLM output differ from expected?
  2. Read eval explanations: eval.*.explanation tells you WHY something failed
  3. Check annotation text: Human feedback describes specific issues
  4. Look for verbosity mismatches: If outputs are too long/short vs ground truth
  5. Check format compliance: Are outputs in the expected format?

Phase 3: Optimize the Prompt

The Optimization Meta-Prompt

Fill in the three placeholders in references/optimization-meta-prompt.md and send it to your LLM (GPT-4o, Claude, etc.) to generate an improved version of the prompt.

Preparing the performance data

Format the records as a JSON array before pasting into the template:

# From dataset + experiment: join and select relevant columns
jq -s '
  .[0] as $ds |
  [.[1][] | . as $run |
    ($ds[] | select(.id == $run.example_id)) as $ex |
    {
      input: $ex.input,
      expected: $ex.expected_output,
      actual_output: $run.output,
      eval_score: $run.evaluations.correctness.score,
      eval_label: $run.evaluations.correctness.label,
      eval_explanation: $run.evaluations.correctness.explanation
    }
  ]
' dataset_*/examples.json experiment_*/runs.json

# From exported spans: extract input/output pairs with annotations
jq '[.[] | select(.attributes.openinference.span.kind == "LLM") | {
  input: .attributes.input.value,
  output: .attributes.output.value,
  status: .status_code,
  model: .attributes.llm.model_name
}]' spans.json

Applying the revised prompt

After the LLM returns the revised messages array:

  1. Compare the original and revised prompts side by side
  2. Verify all template variables are preserved
  3. Check that format instructions are intact
  4. Test on a few examples before full deployment

Phase 4: Iterate

The optimization loop

1. Extract prompt    -> Phase 1 (once)
2. Run experiment    -> ax experiments create ...
3. Export results    -> ax experiments export EXPERIMENT_NAME --dataset DATASET_NAME --space SPACE
4. Analyze failures  -> jq to find low scores
5. Run meta-prompt   -> Phase 3 with new failure data
6. Apply revised prompt
7. Repeat from step 2

Measure improvement

# Compare scores across experiments
# Experiment A (baseline)
jq '[.[] | .evaluations.correctness.score] | add / length' experiment_a/runs.json

# Experiment B (optimized)
jq '[.[] | .evaluations.correctness.score] | add / length' experiment_b/runs.json

# Find examples that flipped from fail to pass
jq -s '
  [.[0][] | select(.evaluations.correctness.label == "incorrect")] as $fails |
  [.[1][] | select(.evaluations.correctness.label == "correct") |
    select(.example_id as $id | $fails | any(.example_id == $id))
  ] | length
' experiment_a/runs.json experiment_b/runs.json

A/B compare two prompts

  1. Create two experiments against the same dataset, each using a different prompt version
  2. Export both: ax experiments export EXP_A --dataset DATASET_NAME --space SPACE, then the same for EXP_B
  3. Compare average scores, failure rates, and specific example flips
  4. Check for regressions -- examples that passed with prompt A but fail with prompt B

Prompt Engineering Best Practices

Apply these when writing or revising prompts:

TechniqueWhen to applyExample
Clear, detailed instructionsOutput is vague or off-topic"Classify the sentiment as exactly one of: positive, negative, neutral"
Instructions at the beginningModel ignores later instructionsPut the task description before examples
Step-by-step breakdownsComplex multi-step processes"First extract entities, then classify each, then summarize"
Specific personasNeed consistent style/tone"You are a senior financial analyst writing for institutional investors"
Delimiter tokensSections blend togetherUse ---, ###, or XML tags to separate input from instructions
Few-shot examplesOutput format needs clarificationShow 2-3 synthetic input/output pairs
Output length specificationsResponses are too long or short"Respond in exactly 2-3 sentences"
Reasoning instructionsAccuracy is critical"Think step by step before answering"
"I don't know" guidelinesHallucination is a risk"If the answer is not in the provided context, say 'I don't have enough information'"

Variable preservation

When optimizing prompts that use template variables:

  • Single braces ({variable}): Python f-string / Jinja style. Most common in Arize.
  • Double braces ({{variable}}): Mustache style. Used when the framework requires it.
  • Never add or remove variable placeholders during optimization
  • Never rename variables -- the runtime substitution depends on exact names
  • If adding few-shot examples, use literal values, not variable placeholders

Workflows

Optimize a prompt from a failing trace

  1. Export full failing traces in one step:
    ax traces export PROJECT --space SPACE --filter "status_code = 'ERROR'" -l 5 --stdout > failing.json
    
  2. Extract the prompt from the LLM span (the errored LLM span when one exists, else the first LLM span):
    jq '[.[] | select(.attributes.openinference.span.kind == "LLM")] | (map(select(.status_code == "ERROR"))[0] // .[0]) | {
      messages: .attributes.llm.input_messages,
      template: .attributes.llm.prompt_template,
      output: .attributes.output.value,
      error: .attributes.exception.message
    }' failing.json
    
  3. Identify what failed from the error message or output
  4. Fill in the optimization meta-prompt (Phase 3) with the prompt and error context
  5. Apply the revised prompt

Optimize using a dataset and experiment

  1. Export the dataset and experiment (ax experiments list --dataset DATASET_NAME --space SPACE finds unknown names):
    ax datasets export DATASET_NAME --space SPACE
    ax experiments export EXPERIMENT_NAME --dataset DATASET_NAME --space SPACE
    
  2. Prepare the joined data for the meta-prompt
  3. Run the optimization meta-prompt
  4. Create a new experiment with the revised prompt to measure improvement

Debug a prompt that produces wrong format

  1. Export spans where the output format is wrong:
    ax spans export PROJECT --space SPACE \
      --filter "attributes.openinference.span.kind = 'LLM' AND annotation.format.label = 'incorrect'" \
      -l 10 --stdout > bad_format.json
    
  2. Look at what the LLM is producing vs what was expected
  3. Add explicit format instructions to the prompt (JSON schema, examples, delimiters)
  4. Common fix: add a few-shot example showing the exact desired output format

Reduce hallucination in a RAG prompt

  1. Find traces where the model hallucinated:
    ax spans export PROJECT --space SPACE \
      --filter "annotation.faithfulness.label = 'unfaithful'" \
      -l 20 --stdout
    
  2. Export and inspect the retriever + LLM spans together:
    ax spans export PROJECT --space SPACE --trace-id TRACE_ID --stdout > spans.json
    jq '[.[] | {kind: .attributes.openinference.span.kind, name, input: .attributes.input.value, output: .attributes.output.value}]' spans.json
    
  3. Check if the retrieved context actually contained the answer
  4. Add grounding instructions to the system prompt: "Only use information from the provided context. If the answer is not in the context, say so."

Troubleshooting

ProblemSolution
ax: command not foundSee references/ax-setup.md
No profile foundNo profile is configured. See references/ax-profiles.md to create one.
No input_messages on spanCheck span kind -- Chain/Agent spans store prompts on child LLM spans, not on themselves
Prompt template is nullNot all instrumentations emit prompt_template. Use input_messages or input.value instead
Variables lost after optimizationVerify the revised prompt preserves all {var} placeholders from the original
Optimization makes things worseCheck for overfitting -- the meta-prompt may have memorized test data. Ensure few-shot examples are synthetic
No eval/annotation columnsRun evaluations first (via Arize UI or SDK), then re-export
Experiment output column not foundThe column name is {experiment_name}.output -- check exact experiment name via ax experiments get
jq errors on span JSONEnsure you're targeting the correct file path (e.g., spans.json from --stdout > spans.json)

FAQ

What does the arize-prompt-optimization skill do?

Optimizes, improves, and debugs LLM prompts using production trace data, evaluations, and annotations. Extracts prompts from spans, gathers performance signal, and runs a data-driven optimization loop using the ax CLI. Use when the user mentions optimize prompt, improve prompt, make AI respond better, improve output quality, prompt engineering, prompt tuning, or system prompt improvement.

How do I install arize-prompt-optimization?

Run npx skills add https://github.com/arize-ai/arize-skills --skill arize-prompt-optimization in your project. The skills CLI detects the agents you use and copies the skill into the right folder. For Claude Code you can also place the skill folder at ~/.claude/skills/arize-prompt-optimization/ (personal) or .claude/skills/arize-prompt-optimization/ (project).

Which AI agents can use arize-prompt-optimization?

Any agent that supports the open Agent Skills format (a folder with a SKILL.md file), including Claude Code, Codex, Cursor, GitHub Copilot, Gemini CLI, Windsurf, Cline, OpenCode and more.

Is arize-prompt-optimization safe to install?

No partner security audit is available yet. Skills can run commands and scripts, so read the SKILL.md and any bundled files before installing.

Who maintains arize-prompt-optimization?

It is published by arize-ai in arize-ai/arize-skills. It has 3,302 recorded installs.

More from arize-ai/arize-skills

View all →

arize-instrumentation

arize-ai/arize-skills

Adds Arize AX tracing to an LLM application for the first time. Detects the stack, routes to the single matching integration doc, wires auto-instrumentation after user confirmation, and verifies traces land. Use when the user wants to instrument their app, add tracing from scratch, set up LLM observability, integrate OpenTelemetry or openinference, or get started with Arize tracing.

AI & Agents3.5K installs

arize-trace

arize-ai/arize-skills

Downloads, exports, and inspects existing Arize traces and spans to understand what an LLM app is doing or debug runtime issues. Covers exporting traces by ID, spans by ID, sessions by ID, and root-cause investigation using the ax CLI. Use when the user wants to look at existing trace data, see what their LLM app is doing, export traces, download spans, investigate errors, or analyze behavior regressions.

AI & Agents3.2K installs

arize-experiment

arize-ai/arize-skills

Creates, runs, and analyzes Arize experiments for evaluating and comparing model performance. Covers experiment CRUD, exporting runs, comparing results, and evaluation workflows using the ax CLI. Use when the user mentions create experiment, run experiment, compare models, model performance, evaluate AI, experiment results, benchmark, A/B test models, or measure accuracy.

arize-dataset

arize-ai/arize-skills

Creates, manages, and queries Arize datasets and examples. Covers dataset CRUD, appending examples, exporting data, and file-based dataset creation using the ax CLI. Use when the user needs test data, evaluation examples, or mentions create dataset, list datasets, export dataset, append examples, dataset version, golden dataset, or test set.

Data & Databases3.1K installs

arize-evaluator

arize-ai/arize-skills

Handles LLM-as-judge and code evaluator workflows on Arize including creating/updating evaluators, running evaluations on spans or experiments, managing tasks, trigger-run operations, column mapping, and continuous monitoring. Use when the user mentions create evaluator, LLM judge, code evaluator, hallucination, faithfulness, correctness, relevance, run eval, score spans, score experiment, trigger-run, column mapping, continuous monitoring, or improve evaluator prompt.

AI & Agents3.1K installs

arize-link

arize-ai/arize-skills

Generates deep links to the Arize UI for projects, traces, spans, sessions, datasets, experiments, labeling queues, evaluators, and annotation configs. Discovers organization and project IDs with the ax CLI and produces clickable URLs for sharing Arize resources with team members. Use when the user wants to link to or open a project, trace, span, session, dataset, experiment, evaluator, or annotation config in the Arize UI.

Frontend & Design3.1K installs

Popular ai & agents skills

View category →

google-agents-cli-publish

google/agents-cli

This skill should be used when the user wants to "publish an agent", "publish my ADK agent", "register an agent with Gemini", "publish to Gemini" (formerly Gemini Enterprise), or needs guidance on the agents-cli publish gemini command. Also use when the user wants to "manage agents in Agent Registry", "list/update/delete registered agents", or "register an MCP server". Covers ADK vs A2A registration modes, programmatic and interactive usage, flag reference, auto-detection from deployment metadata, Agent Registry fleet management, and troubleshooting. Part of the agents-cli skills suite. Do NOT use for deployment (use google-agents-cli-deploy).

AI & Agents513.9K installs

google-agents-cli-eval

google/agents-cli

This skill should be used when the user wants to "run an evaluation", "evaluate my agent", "evaluate my ADK agent", "write an eval dataset", "analyze eval failures", "compare eval results", "optimize agent", or needs guidance on the Gemini platform eval methodology and the Quality Flywheel. Covers eval metrics, dataset schema, LLM-as-judge scoring, and common failure causes. Applies to any agents-cli project, whatever framework the agent is written in. Do NOT use for agent API code patterns (ADK: use google-agents-cli-adk-code), deployment (use google-agents-cli-deploy), or project scaffolding (use google-agents-cli-scaffold).

AI & Agents513.5K installs

skill-creator

anthropics/skills

Create new skills, modify and improve existing skills, and measure skill performance. Use when users want to create a skill from scratch, edit, or optimize an existing skill, run evals to test a skill, benchmark skill performance with variance analysis, or optimize a skill's description for better triggering accuracy.

OfficialAI & Agents416.4K installs

codex-pet

prime-skills/runcomfy-agent-skills

Codex Pet generator on RunComfy. Build a Codex-compatible Codex Pet spritesheet.webp + pet.json from a single reference image, drop it into ${CODEXHOME:-$HOME/.codex}/pets/ / and Codex picks it up as a custom Codex Pet next to the 8 built-ins. This skill produces the exact Codex Pet atlas Codex expects (1536x1872 PNG/WebP, 8 cols x 9 rows, 192x208 cells, 9 animation states — idle, running-right, running-left, waving, jumping, failed, waiting, running, review). Calls OpenAI GPT Image 2 edit ONCE via the local RunComfy CLI as runcomfy run openai/gpt-image-2/edit to produce a canonical Codex Pet pose, then assembles all 9 animation rows programmatically with ImageMagick micro-transforms — no Codex Pro, no $imagegen, no OPENAIAPIKEY required, only RUNCOMFYTOKEN. Triggers on "codex pet", "create codex pet", "make codex pet", "hatch codex pet", "/hatch image", "desktop pet codex", "codex pets", "spritesheet.webp", or any explicit ask to build a custom pet for OpenAI Codex.

AI & Agents402.1K installs

full-output-enforcement

leonxlnx/taste-skill

Overrides default LLM truncation behavior. Enforces complete code generation, bans placeholder patterns, and handles token-limit splits cleanly. Apply to any task requiring exhaustive, unabridged output.

AI & Agents401K installs

executing-plans

obra/superpowers

Use when executing an implementation plan in the current session as the implementer yourself — your human partner chose inline execution, or no subagent tool is available

AI & Agents245.7K installs