# Decision Points in AI Agent Development
# Self-Correction Retry
🎯 The Hook
When your LLM output breaks, are you just blindly resending the same prompt? Self-correction retry feeds back *what went wrong* so the model can fix itself. But here's the catch: beyond 3 retries, improvement almost never happens. Knowing when to stop is as important as knowing when to retry.
📋 Overview
Self-correction retry controls how many times you re-prompt an LLM after its output violates a schema or falls short on quality, injecting error details into context each time. This is fundamentally different from network retries (resending the identical request). By providing specific feedback about what went wrong, you give the model a real chance to produce correct output on the next attempt. LLM outputs are probabilistic -- missing JSON brackets, out-of-range values, and incomplete responses happen routinely. Self-correction retry is one of the most practical strategies for handling these errors.
🔍 Decision Points
The primary driver is failure_cost: how much damage does a bad output cause downstream? Applying the same retry count to all errors is wasteful, so differentiate by error type.
Syntax-level errors (malformed JSON, type mismatches) almost always resolve with a single feedback round. Semantic-level errors (out-of-range values, nonexistent ID references) may improve with feedback, but if the second attempt fails, it's a structural problem. Quality-level errors (incomplete answers, missing information) are subjective and rarely improve through retries -- invest in prompt engineering instead.
💡 Key Details
Reference values to keep in mind 📊
- General case: 1-3 retries. If no improvement after 2, likely a structural issue
- Structured output (JSON Schema): 1-2 retries. Using response_format yields high first-attempt success rates
- High failure_cost domains (financial, legal, medical): 2-3 retries. Escalate to humans if quality plateaus
- Low failure_cost domains: 0-1 retries. If fallbacks exist, fail fast for efficiency
Error messages should be short and specific 🎯 Not "output is invalid" but "the delivery_date field is a past date; please specify a future date." Spell out what's wrong and what's expected. Keep error messages under ~200 tokens since they consume context budget.
⚖️ Trade-offs
Too few retries means discarding fixable errors. Throwing away output that's only missing a closing bracket? That's wasteful.
Too many retries and costs explode ⚡ If one LLM call takes 30 seconds, 5 retries means 2.5+ minutes of waiting. Each retry appends error messages to the context, causing cumulative token growth. Worst case, you hit context length limits and trigger an entirely different failure mode.
If the same error type appears twice in a row, question the prompt before attempting a third retry. Repeated identical errors signal that the LLM cannot produce correct output with the current prompt-schema combination.
🛠️ Use Cases
JSON schema violations: Provide specific error feedback; typically fixed in 1 retry. Using Structured Outputs (response_format) eliminates most syntax-level retries entirely.
Business rule violations (e.g., delivery date in the past): Include concrete constraints and current state in feedback. If 2 retries don't help, pivot to prompt redesign.
Quality shortfalls ("analyze from 5 perspectives" returns only 3): Try once; if no improvement, accept partial results or split the prompt into smaller generation tasks.
Persistent identical errors: Consider lowering temperature, simplifying the prompt, trying a different model, or escalating to a human operator 🔄
#
AIAgents# #
SoftwareArchitecture#
Show more
The loudest voices stoking fears about AI dangers have made tremendous headway in the past two weeks. AI technology has not taken some unexpected, dangerous turn, but the hype around it — propelled by what appears to be a well orchestrated PR campaign — has drummed up considerable fear. I worry that it represents a setback for our field.
I have written frequently that fears of AI are overhyped. AI’s capabilities can be uncannily human-like and unpredictable, and it’s rational to worry when people who are directly involved express concerns. But I see the problems as a sign of the engineering work that ahead, rather than insurmountable barriers or the sky falling. AI technology continues to advance — which is a good thing! — but technical advances, poorly understood by the public, give those who seek to generate hype repeated opportunities to do so.
First, I don’t see any step up in the risk of human extinction from AI compared to a few months ago. The theories about this remain the same fantastical, science fiction scenarios as a few months ago. The biggest change in AI risk is its cybersecurity capabilities — a topic which we should take seriously — but this, too, will not lead to the end of the world.
The most notable recent event leading to increased fear was when an OpenAI team deployed an agent swarm that hacked into Hugging Face. Much of the popular press contained significant hype. For example, some publications reported that a swarm of 1,200 agents carried out the attack. While this was technically accurate, as I write this, I have about 1,300 processes running on my laptop. Yes, the ability to get large swarms of agents to work in parallel on a task is a significant technical advance, And, in computing, many processes run at the same time. So this shouldn’t be seen as some magical capability.
Additionally, OpenAI’s buggy sandboxing and monitoring processes were key to enabling this incident. Fixing these bugs and putting in place improved monitoring would be appropriate fixes, not pausing AI. There are many well known ways to attack software systems. The main advantage of AI agents is that they are relentless. They will tirelessly try many tactics — and have the patience to chain vulnerabilities together — that previously would have taken an infeasible amount of human effort. But in the long term, I believe the advantage will lie with defenders (because they have more information with which to identify bugs, which they can fix), but the cyber-threat landscape has changed significantly. There are still bottlenecks to identifying and exploiting a vulnerability. AI agents still have to try a lot of things to see what works, and taking these actions takes time and might be detected by defenders. This is why, even though it is now easy to obtain versions of leading open weight models that have had their guardrails removed or weakened, so they will not refuse to try to execute cyber attacks, the world has not ended.
I am also concerned about the anthropomorphization of AI in a lot of reporting, where LLMs and agents are unnecessarily treated as if they were people. If I wield a hammer, miss a nail, and accidentally dent the wall, it’s not the fault of the hammer. The problem lies in how I used the hammer. Similarly, if I prompt an agent and it hacks into someone else’s system, the responsibility lies with me, not the agent.
Of course, we want to build systems that are as safe and predictable as possible. (For example, an unsafe hammer would be one whose head randomly flies off under normal use.) Today’s agentic systems are not predictable, but I see no reason why, by applying sound engineering practices, we won’t be able to make them extremely safe to use. One new element in the forecasts of AI-enabled doom is AI companies disclaiming responsibility for their own products. “I didn’t do it; my out-of-control agent did!” There’s a balance to be struck between the responsibility of the tool maker and the tool user, but when something goes wrong, let’s hold the people building and/or using the hammer responsible, rather than the hammer. (By the way, if you’re worried about AI bioweapon risk, David Bellamy has a great post on why this, too, is overhyped. Briefly, the bottleneck in building a bioweapon is not intelligence, but lab work and manufacturing.)
Pausing AI progress will create much more harm than benefit. First, our adversaries will certainly not slow down. Second, engineering requires discovering problems empirically so we can fix them. If we pause AI by a decade, we will also delay finding and implementing safety engineering fixes by about the same duration.
Of course, the incentive to stoke fears — for regulatory capture, to garner attention, or to make one’s technology seem more powerful — remains the same as before. Disclaiming responsibility is a new one. Taking a hard technical look at the actual risks however, I see little factual basis for the degree of fear that’s been stoked up. We still have hard research and engineering work ahead to improve AI safety, but the beneficial applications continue to vastly outweigh the risks, and we should keep building.
[Original text (with links): ]
Show more