Optimize
Prompt optimization from production runs
Version every prompt, let the optimizer read live runs and propose changes with evidence. No eval suite required to start.
Why runtime control
A prompt change has no compiler to catch it
A prompt change is a production change with no type checker and no failing test. The only way to know a rewrite helped is evidence: the live runs it would have improved, the scores it moves, the reviewer who confirms it. That takes managed prompts so versions are real objects, an optimizer that reads your production runs, and human judgment where it counts.
Pydantic Logfire has all of it next to the telemetry it explains, so the loop closes.
How it works
One continuous loop, from failure to fix
- Fail A bad run is a trace in Logfire, one of the failures scattered across your traffic.
- Propose The optimizer reads production runs and proposes a prompt edit. When the fault isn't the prompt, it names the real cause.
- Confirm Accept the diff or gate promotion on an eval when you want the change measured against a baseline.
- Roll out Move a label to a new version, canary it on a slice of traffic before rolling out to everyone.
What you get
Find it, ship it
-
Prompts
Every prompt is a versioned object with history, not a string pasted into three services. A change is a new version you can diff and roll back to.
-
Managed variables
Any Pydantic model becomes a versioned variable, from a boolean flag to a whole agent config. Mark one external for web and mobile.
-
Evidence-cited proposals
The optimizer reads recent production runs and proposes one prompt edit at a time. If a claim can't cite a run you can open, it's rejected.
-
Scenarios
A named test case with its real message sequence, template parameters and tool calls. Sweep a whole dataset, up to 500 cases per run.
-
Rollouts
Point production at one version and a canary at another, split 90/10. Diff them line by line, then move the label to promote or roll back.
-
Measured in your traces
Every resolution tags its spans with the label and version, so you compare latency, tokens and cost between v1 and v2.
Use cases
What people use Optimize for
- Read how to optimize
Fix a failure you couldn't see
The optimizer reads production runs at scale where rare failures hide, finds the pattern behind them, and offers the prompt edit with evidence.
- Use prompts in your app
Change a prompt without shipping code
Edit the version in Logfire, promote it with a label, roll it back if it was wrong. No pull request, no release window, no redeploy.
- Read the rollouts guide
Roll a model change out to 5% first
Percentage rollouts and attribute targeting, with every resolution recorded as a span, so you can query the variants like anything else.
Customer stories
Teams who iterate faster than they deploy
-
How Overjoy caught an agent burning 20x its usual spend
“Now we can see exactly what's being called, how an agent thinks, what it costs”
Ishaan Nagpal Founding Engineer
-
How MindsDB cut agent experiments from weeks to hours
10x Better agent performance, one month after the switch
-
How Datalayer cut the tokens a data question costs
90% Best case reduction in token use for data analysis tasks
FAQ
What is prompt optimization?
Prompt optimization is improving a prompt based on evidence from real runs rather than guesswork. In Pydantic Logfire, the optimizer reads what actually happened across many runs, finds the pattern behind the failures, and proposes a change you can measure against the current version.
How does the Logfire optimizer decide what to change?
Logfire reads recent production runs with failures weighted highest, and proposes one prompt edit at a time. Every claim in the proposal cites the runs behind it. If a proposed change can't point to a run you can open, Logfire rejects it and the optimizer tries again. You review the diff and accept it before anything about the running agent changes.
Do I need an eval suite to optimize prompts?
No. The optimizer starts from your live traces: it reads recent runs, finds the failures worth fixing, and proposes the change with the runs as evidence. An eval suite is useful once you want to gate promotion on numbers, because it turns a proposal into a measured comparison against a baseline. Tracing alone is enough to begin.
What happens when the problem isn't the prompt?
The Logfire optimizer says so instead of changing the prompt. When failures trace to a down dependency, a broken tool, or a quota, it files a finding that names the real cause and points at the runs that prove it. Findings are grouped by owner: provider availability, quota and billing, tools and integrations, runtime and infrastructure, configuration, and model limitations.
Can I roll a prompt change out gradually in Logfire?
Yes. Prompts are versioned and served by label, so a new version can take a fraction of traffic before it takes all of it. Because the version that served each request is recorded on its trace, splitting the results by version is a SQL query. A regression shows up in the scores of a slice before the whole user base sees it.
Get started with Logfire for free
Sign up today and see your first trace in under 2 minutes
01 — Install
$ uv add logfire
Resolved 7 packages in 128ms
Installed 7 packages in 89ms
+ logfire 02 — Instrument
import logfire
logfire.configure()
logfire.info('Hello {name}', name='world') Free up to 10m records per month No credit card needed