Apply to my task
arXiv:2610.21393 ★ 90 Oct 15, 2026

Self-Guided Reasoning: Checking Data for Errors with Code the Model Writes Itself

Key result

Finding: if you ask a model to find errors in a table “just by looking,” it catches typos and missing values but falls apart on anything that requires calculation. The Self-Guided Reasoning method catches far more limit, time-window and weight violations. The model decides what to check, and the math is done by code that it writes and runs itself. If the code crashes, it reads the error and fixes it. On the hard variants (GPT-4.1, routing benchmarks), the share of errors caught rose from 14–60% to 90–100%, and the report is built on the code's output, not on guesses.

01

TL;DR

Self-Guided Reasoning is a three-step technique for checking tables and structured data. First, the model works out what the data is and which rules it should follow. Then it writes and runs its own validation code against those rules. Finally, it builds an error report from the code's output, not by eyeballing, and fixes the data.

The key finding: if you ask a model to find errors in data “just by looking,” it does a good job on typos, missing fields and simple rules like “weight can't exceed vehicle capacity.” But it falls apart on checks that require adding, comparing and calculating step by step (time windows, mileage limits). The more rows, rules and errors, the worse it gets. The model isn't calculating, it's eyeballing a guess: it catches some errors and misses others. Re-running the check only helps on simple errors.

The fix is to move the math out of the model's “head” and into code. The model decides what to check, writes the functions and runs them. If the code crashes, it reads the error message and fixes it. The answer is built on the code's output. In the paper's main runs (GPT-4.1), the variants where direct checking caught 14–60% of errors went to 90–100% with this method.

Want this for your own case? Apply this study to your task: AI adapts its method to what you are working on and writes the prompt.

02

Method Blueprint

STEP 1: Data analysis → task type, required sections, rules (+ self-check of this analysis)
STEP 2: Insight generation → validation path → description of each function (input/output) → code → run
        └ if the code crashes → error text goes back to the model → fix → re-run
STEP 3: Report → type, location and cause of each error → corrected version of the data

In our adaptation, you can run all the steps in a single conversation if your chat can execute code (Code Interpreter, data analysis in Claude, Claude Code, Cursor). Without code execution the method is pointless.

03

Example

Our illustration, not from the paper (the paper used benchmark routing instances in a text file format).

Task: A logistics coordinator at an online store in Chicago is preparing tomorrow's export: 80 addresses, delivery windows, order weights, 5 vans with load capacity and mileage limits. Before uploading it to the route-planning service, they need to catch the errors: a “18:00–10:00” window, an order heavier than the cargo bay, zero coordinates, an address with no phone number, a van whose shift is too short for its route.

Prompt:

Below is tomorrow's order export (80 rows) and the parameters of 5 vans.
Find every error before it goes into the route-planning service.
Don't check by eyeballing. Work in three steps.

STEP 1. Analysis.
Determine: what kind of task this is, which sections of the data are required,
which constraints must hold (weight, time windows, shift length,
mileage limit, field format). Check your analysis for contradictions
with the data itself and fix them. Output a short summary.

STEP 2. Validation with code.
Based on the summary, make a plan: where format errors are likely,
and where constraint violations are likely. For each item in the plan, describe
a function: what it does, what it takes, what it returns.
Then write Python code and run it.
For every problem found, the code must print: row number,
field, value found, which rule was violated.
If the code crashes, read the error, fix it and run it again.

STEP 3. Report.
Match the code's output against the source data. Give a table:
error type / row / what's wrong / likely cause.
Then propose a corrected version of the data. Separately show
what you changed, and flag the edits you're not sure about.

Data: {paste or attach the file}

Result: The model first gives a short summary: task type, required fields, list of rules. Then it shows the validation plan, runs the code and prints a list of violations with row numbers. If the code crashes, you'll see the fix and the re-run. At the end you get an error table with type, location and cause, plus a corrected export with the questionable edits flagged.

04

Why It Works

The model's weakness. A model generates text from patterns; it has no counter or calculator. A check like “total weight on the route is no more than 1500 kg” or “arriving at 14:20 falls inside the 14:00–14:15 window” requires exact chains of arithmetic. The more rows and rules, the more of these chains. They pile up, and the model starts missing errors. Re-running the “eyeball” check just repeats the same weakness.

The model's strength. The model understands data structure well, knows the typical rules of a domain and writes working code. Code calculates precisely however many rows there are (the paper tested instances with 50 and 100 nodes).

How the method uses this. The model handles what to check; the code handles the checking. Step 1 locks in the rules so the code doesn't check random things. Step 2 turns the rules into functions that print details for every error found. Step 3 forces the model to rely on the code's output, not on guesses.

Control knobs (our suggestions; the paper has no ablation study testing these parts separately): - Self-check in step 1 → the paper always uses it; you might drop it for simple data and keep it for unfamiliar structures. If the model misreads the rules, all the code will check the wrong thing. - The “print row, field, value, rule” requirement → without it the report will be vague. You need it to pinpoint where each error is. - The “code error → fix” loop → keep it no matter what, otherwise the first typo in the code kills the process. - Function description (input/output) → part of the paper's method; the idea is that the model first states the task in words before writing code. - Flagging uncertain edits → add it so you don't accept fixes blindly.

05

Prompt Template

The paper's own prompts are in its Appendix D, partly abbreviated and written for routing-problem files. The template below is our adaptation of the three stages for general tables, not the paper's wording.

You are given a dataset: {data_description}.
Your task is to find errors before the data goes into {where_the_data_goes}.
Don't check by eyeballing: do numerical and logical checks with code.

<Stage_1_Analysis>
Determine:
- task type: {what_this_object_is}
- required sections/fields that correct data must contain
- constraints that must hold: {list_of_rules}
Check your analysis for contradictions with the contents of the data
and fix it. Output a short summary.
</Stage_1_Analysis>

<Stage_2_Insights>
1. Based on the summary, determine where format errors are likely
   (missing values, invalid values) and where rule violations are likely.
   Lay out a step-by-step validation path.
2. For each step, describe a function: what it does, what it takes,
   what it returns.
3. Write code based on these descriptions. For every problem found,
   the code prints: where (row/field), what was found, which rule was violated.
4. Run the code. If it crashes, read the error message,
   fix the code and run it again. Repeat until it completes.
5. Collect the code's output into a list of insights about the errors.
</Stage_2_Insights>

<Stage_3_Report>
Match the insights against the source data. Give a report:
error type / location / what's wrong / likely cause.
Then fix the data. Show exactly what was changed,
and flag the edits you're not sure about.
</Stage_3_Report>

Data:
{data}

Fill in: {data_description} — what the table or file is; {where_the_data_goes} — the system or process where an error is costly; {what_this_object_is} — the type of task or process; {list_of_rules} — the rules you already know yourself (the more precise, the better); {data} — the pasted text or file.

🚀 Quick start — paste this into a chat that can run code:

Here is a template for checking data with code the model writes itself.
Adapt it to my task: {your task: what data it is and where it's going}.
Ask me questions to fill in the fields.

[paste the template above]

The LLM will ask what the data is, which rules it must satisfy and what happens if there's an error. That's so it locks in the right rules at the analysis stage; otherwise the code will check the wrong thing. It'll take the template's structure and fit it to your table.

06

Limitations

⚠️ You need code execution: without Code Interpreter, Claude Code, Cursor or something similar, the method turns back into a plain eyeball check and loses its point.

⚠️ The code only checks what the model thought to check: if in step 1 it misunderstood the rules or missed an important constraint, the code will faithfully check the wrong thing. This is the weakest link. Better to list your rules explicitly.

⚠️ Synthetic errors in a single domain: the researchers injected the errors into the data artificially (routing and bin packing). Real-world “dirty” data can be sneakier. The authors didn't test transfer to CRMs, accounting or price lists.

⚠️ False positives: in the paper's appendix, on error-free instances the self-guided method flagged no false errors, while direct GPT-4.1 flagged up to 13 (in backhaul variants). That was on routing benchmarks; still test on a file you know is clean so you don't get “errors” where there are none.

⚠️ Iteration helps on simple cases, not hard ones: repeated eyeball passes get close to 100% only on simple errors. On complex combinations of rules they don't help, and that's where you need code.

⚠️ Time: the method is a bit slower than a direct request (in the paper's timing table, 6–17 minutes vs 6–15 minutes for direct checking; the paper does not say whether this is per instance or per batch).

07

How They Studied It

The researchers took 48 variants of vehicle routing problems, from simple ones to those where up to six types of constraints apply at once. Into each variant they injected up to 200 errors across 20 instances: format errors (missing values, invalid values) and rule violations (capacity, time windows, mileage limits and so on). The main model was GPT-4.1. First they measured how the model does directly. Then they compared that with the three-step method.

The picture came out clear. In single-constraint variants, the model catches format errors (about 90–99%) and capacity violations (about 83–92%) well. Backhaul rules, about 61–64%. Time-window and distance-limit errors, close to 0%. The more errors, rows and constraint types, the worse it gets: with 100 nodes the results are lower than with 50, and on the hardest variants the direct approach found only 14% to 31% of errors. Repeated iterations (“find, fix, look again”) pushed the simple variants close to 100%, but the hard ones stayed “far from ideal.”

Self-Guided pushed results to 90–100% on all 48 variants (GPT-4.1). For example, the time-window variant rose from 66% to 95%, and one of the hardest went from 14% to 99%. The method was also tested on bin packing (smaller gains: 94.5% to 97.5% and 90% to 94.5%) and with GPT-4o and Claude Opus 4 on eight variants, where it mostly stayed above 90%.

The surprise: repeated runs don't help where the model can't calculate. It's not a question of how many attempts, it's a question of approach: “looking” versus “calculating with code.” The practical takeaway: if a check requires arithmetic, don't ask the model to think harder, ask it to write the check.

08

Adaptations and Extrapolations

🔧 Technique: add a second pass → catch what slipped through the first time

After the data is fixed, run the same checks again:

You've fixed the data. Run the same validation code on the corrected version.
Show whether any violations remain. If they do, repeat step 3.

In the study, iterations helped on simple errors. Here they verify that the fix didn't create new problems.

🔧 Technique: test on clean data → guard against false positives

First give the model a file you know for sure has no errors, and see whether it finds any “problems.” If it does, tighten the rules in step 1.

Extrapolation: a rule for your agent (CLAUDE.md / AGENTS.md)

The principle “check numbers with code, not in your head” can be baked into an agent's instructions. This is my own extension; it's not in the paper:

Data validation rule:
- Any check that requires adding, comparing ranges or calculating
  step by step must be done with a script, not by reasoning.
- For every problem, the script prints the row, field, value and the rule violated.
- If the script crashes, fix it based on the error text and run it again.
- Base your report on the script's output. If there is no output, don't claim there are no errors.
09

Resources

  • Paper: Self-Guided LLM Reasoning for Error Diagnosis in Vehicle Routing Problems
  • Authors: Ni Zhang, Zhiguang Cao (Singapore Management University), Jianan Zhou (Nanyang Technological University), Yue-Jiao Gong (South China University of Technology)
  • Related work mentioned: MOID (error diagnosis via solver results), OPRO, FunSearch, ReEvo, AFL
  • The paper's prompts for the three stages are in Appendix D (partly abbreviated)

Research digest

Key result

Finding: if you ask a model to find errors in a table “just by looking,” it catches typos and missing values but falls apart on anything that requires calculation. The Self-Guided Reasoning method catches far more limit, time-window and weight violations. The model decides what to check, and the math is done by code that it writes and runs itself. If the code crashes, it reads the error and fixes it. On the hard variants (GPT-4.1, routing benchmarks), the share of errors caught rose from 14–60% to 90–100%, and the report is built on the code's output, not on guesses.

Principle

Three steps, and each does one job. 1. Analysis. The model figures out what the data is, which fields are required and which rules apply. Then it checks its own analysis for contradictions with the data itself. 2. Code. The model drafts a validation plan, describes each function (what it takes, what it returns), writes the code and runs it. Code crashed? The error text goes back to the model, it fixes the code and runs it again. 3. Report. The model matches the code's output against the data. It produces a table: error type, row, what's wrong, likely cause. Then it sends back a corrected version. The model answers the question “what should we check,” the code answers the question “is it violated or not”. Think of an editor and an accountant. The editor knows which numbers matter. But adding up columns gets handed to the calculator, not done in their head. The key requirement: for every finding, the code prints the row, field, value and the rule violated.

Why it works

A model has no counter. It generates text from patterns. A check like “total weight on the route is no more than 1500 kg” or “arriving at 14:20 doesn't fit the 14:00–14:15 window” requires an exact chain of calculations. The more rows and rules, the longer the chains. The model starts catching some errors and missing others. Repeated eyeball passes don't save you. They get close to 100% only on simple errors. On complex combinations of rules, the model repeats the same weakness. On the other hand, it understands data structure well, knows the typical rules of a domain and writes working code. The wild part: the very same model (GPT-4.1), with code in hand, goes from 14–60% to 90–100% of errors found on the hard variants. Code calculates just as precisely every time, whatever the size. The cost is small: the method is slower than a single request; in the paper's timing table it took 6–17 minutes vs 6–15 for direct checking.

When to apply

Tables and exports before they're loaded into a system → especially when there are many rows and the rules require arithmetic: sums, limits, time windows, comparing fields across rows. Examples: orders and vehicles for route planning, price lists, warehouse stock levels, shift schedules. NOT a fit if your chat can't run code (Code Interpreter, data analysis in Claude, Claude Code, Cursor). Without it, you're back to eyeballing. Also not a fit when the errors are about meaning rather than numbers and logic. Careful: the authors tested the method only on artificial errors in routing and bin packing. It wasn't tested on real CRMs or accounting. Real-world errors can be sneakier.

Mini recipe

1. Make sure code can run: you need a chat that executes Python or an agent like Claude Code. No code execution, no point in this method. 2. State the goal: where the data is going and what an error would cost. The model will pick what to check more accurately. 3. Write out your rules: weight, windows, shift, field format. The more precise, the better. This is the weakest link: the code only checks what the model thought to check. 4. Ask for a summary and a self-check of the analysis: the paper always includes it. Our suggestion: on familiar, simple data you might skip it; on an unfamiliar structure, keep it. 5. Demand detailed output from the code: row, field, value found, rule violated. Without it the report will be vague. 6. Let it fix the code: crashed — it reads the error, fixes it, runs again. Without that loop, the first typo in the code kills everything. 7. Ask it to flag questionable edits: that way you won't accept the corrected export blindly. 8. Run a file you know is clean: on routing benchmarks the method flagged no false errors on clean instances, but check on your own data that the model isn't inventing errors.

Examples

Our illustration, not from the paper. [BAD]: `Here's tomorrow's order export, find all the errors` [GOOD]: `Below is the order export (80 rows) and the parameters of 5 vans. Find the errors before upload to the route-planning service. Don't check by eyeballing. STEP 1: determine the task type, required fields and rules (weight no more than load capacity, delivery window not “18:00–10:00”, coordinates not zero, every address has a phone number, van shift not shorter than the route). Check the analysis for contradictions with the data. STEP 2: draft a validation plan, describe each function (what it takes, what it returns), write Python code and run it. The code prints: row, field, value, rule violated. If the code crashes, fix it and run it again. STEP 3: give a table “error type / row / what's wrong / cause”, then the corrected export. Flag the edits you're not sure about.` With the bad request, the model skims the data, catches the zero coordinates and misses the van whose shift is too short. With the good one, that check is done by code, and it doesn't get lost among 80 rows.

In plain words

Language models flat-out can't do mental math — they simply don't have a built-in calculator. When you feed a model a complex table full of tonnage and time slots, it isn't adding up pounds, it's just picking likely words. The more conditions stack on top of each other, the faster the arithmetic goes off the rails, turning deep analysis into plain old guessing and missed screwups.

It's like hiring an accountant, taking away their Excel and making them balance the books purely by eye. On paper they nod confidently, but in practice they're guaranteed to miss an overloaded truck or a wild delivery window like "18:00–10:00". In the paper's tests, the more errors, rows and constraint types, the more the model missed.

The fix is the Self-Guided Reasoning approach, which knocks the nonsense out of the model in three steps. First it pulls the hard logic rules out of the task, then it writes its own validation code in Python for those conditions, runs it and judges the data based on what the script actually reports. No guesswork: errors get caught not by the model's imagination but by deterministic code.

The method was tested on vehicle routing benchmarks (50 and 100 locations; capacity, time windows, distance limits) and on bin packing, with injected errors. The same idea may carry over to CRM exports, warehouse inventory or financial reports, but the authors didn't test that. Where your tables have hard numeric limits, validation through code is worth trying.

Stop begging the model to “check it one more time” — in the study, repeated self-review helped on simple data but barely moved the hard cases. Make the model the architect of the tests, not the calculator, and turn its code loose on real data. Either you adopt generating validation scripts, or you keep wondering why your logistics keeps coming apart at the seams.

AI lab assistant

Apply this study to your task

Describe what you're working on. AI takes the method and the measured results from this paper and adapts them to your case, or writes a ready prompt built on them.

Based on Self-Guided Reasoning: Checking Data for Errors with Code the Model Writes Itself arXiv:2610.21393

Sign in to apply this study New accounts get 50 free credits.