npx skills add ...
npx skills add github/awesome-copilot --skill 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.
npx skills add github/awesome-copilot --skill arize-prompt-optimization
SPACE— All--spaceflags and theARIZE_SPACEenv var accept a space name (e.g.,my-workspace) or a base64 space ID (e.g.,U3BhY2U6...). Find yours withax spaces list.
LLM applications emit spans following OpenInference semantic conventions. Prompts are stored in different span attributes depending on the span kind and instrumentation:
| Column | What it contains | When to use |
|---|---|---|
attributes.llm.input_messages | Structured chat messages (system, user, assistant, tool) in role-based format | Primary source for chat-based LLM prompts |
attributes.llm.input_messages.roles | Array of roles: system, user, assistant, tool | Extract individual message roles |
attributes.llm.input_messages.contents | Array of message content strings | Extract message text |
attributes.input.value | Serialized prompt or user question (generic, all span kinds) | Fallback when structured messages are not available |
attributes.llm.prompt_template.template | Template with {variable} placeholders (e.g., "Answer {question} using {context}") | When the app uses prompt templates |
attributes.llm.prompt_template.variables | Template variable values (JSON object) | See what values were substituted into the template |
attributes.output.value | Model response text | See what the LLM produced |
attributes.llm.output_messages | Structured model output (including tool calls) | Inspect tool-calling responses |
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.attributes.input.value contains the user's question. The actual LLM prompt lives on child LLM spans -- navigate down the trace tree.attributes.input.value has tool input, attributes.output.value has tool result. Not typically where prompts live.These columns carry the feedback data used for optimization:
| Column pattern | Source | What it tells you |
|---|---|---|
annotation.<name>.label | Human reviewers | Categorical grade (e.g., correct, incorrect, partial) |
annotation.<name>.score | Human reviewers | Numeric quality score (e.g., 0.0 - 1.0) |
annotation.<name>.text | Human reviewers | Freeform explanation of the grade |
eval.<name>.label | LLM-as-judge evals | Automated categorical assessment |
eval.<name>.score | LLM-as-judge evals | Automated numeric score |
eval.<name>.explanation | LLM-as-judge evals | Why the eval gave that score -- most valuable for optimization |
attributes.input.value | Trace data | What went into the LLM |
attributes.output.value | Trace data | What the LLM produced |
{experiment_name}.output | Experiment runs | Output from a specific experiment |
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.md401 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 Keysax spaces list to pick by name, or ask the userax projects list -o json --limit 100 and present as selectable optionsax ai-integrations list --space SPACE to check for platform-managed credentials. If none exist, ask the user to provide the key or create an integration via the arize-ai-provider-integration skill.env files or search the filesystem for credentials. Use ax profiles for Arize credentials and ax ai-integrations for LLM provider keys. If credentials are not available through these channels, ask the user.Once you have the span data, reconstruct the prompt as a messages array:
If the span has attributes.llm.prompt_template.template, the prompt uses variables. Preserve these placeholders ({variable} or {{variable}}) -- they are substituted at runtime.
Join the two files by example_id to see inputs alongside outputs and evaluations:
Look for patterns across failures:
eval.*.explanation tells you WHY something failedUse this template to generate an improved version of the prompt. Fill in the three placeholders and send it to your LLM (GPT-4o, Claude, etc.):
Format the records as a JSON array before pasting into the template:
After the LLM returns the revised messages array:
ax experiments export EXP_A and ax experiments export EXP_BApply these when writing or revising prompts:
| Technique | When to apply | Example |
|---|---|---|
| Clear, detailed instructions | Output is vague or off-topic | "Classify the sentiment as exactly one of: positive, negative, neutral" |
| Instructions at the beginning | Model ignores later instructions | Put the task description before examples |
| Step-by-step breakdowns | Complex multi-step processes | "First extract entities, then classify each, then summarize" |
| Specific personas | Need consistent style/tone | "You are a senior financial analyst writing for institutional investors" |
| Delimiter tokens | Sections blend together | Use ---, ###, or XML tags to separate input from instructions |
| Few-shot examples | Output format needs clarification | Show 2-3 synthetic input/output pairs |
| Output length specifications | Responses are too long or short | "Respond in exactly 2-3 sentences" |
| Reasoning instructions | Accuracy is critical | "Think step by step before answering" |
| "I don't know" guidelines | Hallucination is a risk | "If the answer is not in the provided context, say 'I don't have enough information'" |
When optimizing prompts that use template variables:
{variable}): Python f-string / Jinja style. Most common in Arize.{{variable}}): Mustache style. Used when the framework requires it.| Problem | Solution |
|---|---|
ax: command not found | See references/ax-setup.md |
No profile found | No profile is configured. See references/ax-profiles.md to create one. |
No input_messages on span | Check span kind -- Chain/Agent spans store prompts on child LLM spans, not on themselves |
Prompt template is null | Not all instrumentations emit prompt_template. Use input_messages or input.value instead |
| Variables lost after optimization | Verify the revised prompt preserves all {var} placeholders from the original |
| Optimization makes things worse | Check for overfitting -- the meta-prompt may have memorized test data. Ensure few-shot examples are synthetic |
| No eval/annotation columns | Run evaluations first (via Arize UI or SDK), then re-export |
| Experiment output column not found | The column name is {experiment_name}.output -- check exact experiment name via ax experiments get |
jq errors on span JSON | Ensure you're targeting the correct file path (e.g., trace_*/spans.json) |