SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 2406.12692 · 2024

MAGIC: Generating Self-Correction Guideline for In-Context Text-to-SQL

arXiv · PDF · Open in the Atlas

Code that ran

3 of 3 samples (functions and classes) lifted from this paper's linked repositories executed on a synthesized input in Syntology's jail (0 of them constructed an object rather than computing a result; 0 honoured the contract we drafted, 0 violated it and 0 have no contract verdict; 3 failures of our instrument; 0 no recorded run), measured 2026-11-22; repository links from the Papers with Code archive attributed under CC BY-SA, no affiliation; bodies inline only under a permissive licence as GitHub detects it. Not a reproduction of the paper's results.

"Ran" means the function executed on a synthesized input and returned a value. It is not a reproduction of the paper's results. This record, dated, as JSON: /api/ran/2406.12692.json · badge: /api/ran/2406.12692.svg

Each repository's role is a label: a classifier's output recorded on the link, or, where no role is recorded, what the Papers with Code archive marked. The line under it names its basis. Neither says who wrote the code.

RepositoryRoleRan
microsoft/synqo canonical (classifier label)
classifier basis: census
3 ran · 0 no recorded run
FunctionStatusWhere it lives
execute_query Ran
ran; our contract draft was wrong, not the code
microsoft/synqo/magic/self_correction_with_guideline.py
code served (permissive licence) · get_code("c8cfa863ef9d7dfb")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned list, ndim 2, dtype family float; no output shape is stated. The image it ran in was not recorded. If your copy returns the same type and ndim on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import sqlite3
import tempfile
import os

# Create a temporary SQLite database for testing
temp_dir = tempfile.mkdtemp()
db_path = os.path.join(temp_dir, "test.db")

# Initialize the database with a simple table
conn = sqlite3.connect(db_path)
cursor = conn.cursor()
cursor.execute('''
    CREATE TABLE test_table (
        id INTEGER PRIMARY KEY,
        name TEXT,
        value INTEGER
    )
''')
cursor.execute("INSERT INTO test_table (name, value) VALUES ('Alice', 100)")
cursor.execute("INSERT INTO test_table (name, value) VALUES ('Bob', 200)")
conn.commit()
conn.close()

# Define the arguments for execute_query
ARGS = {
    "query": "SELECT * FROM test_table",
    "db_path": db_path
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
none outside the standard library — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type list, ndim 2, dtype family float — a list output has no array shape of its own; none is stated
dtype family
int means an integer dtype; float means any other dtype the instrument saw, bool and complex included (fixture_check.py records only these two families)
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
extract_sql_query Ran
ran; our contract draft was wrong, not the code
microsoft/synqo/utils/sql_extractor.py
code served (permissive licence) · get_code("9fcf08e159dfba46")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned str. The image it ran in was not recorded. If your copy returns the same type on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import re

def extract_sql_query(input_text, return_None=True, output_of_gpt=True, to_return_val=None):
    try:
        input_text = input_text.replace('YOU MUST ONLY RETURN SQL.', ' ').strip()
        cleaned_input_text = input_text.strip().replace('\n', ' ').replace('\r', ' ').replace('\t', ' ')
        matches = re.findall('```sql(.*?)```', cleaned_input_text, re.DOTALL)
        if matches:
            latest_sql_query = matches[-1]
            latest_sql_query = latest_sql_query.replace('\\n', ' ').strip()
            return latest_sql_query
        elif return_None == True:
            return None
        else:
            input_text = input_text.split('SQL: ')[-1:][0].split('Revised_SQL: ')[-1:][0].strip()
            if to_return_val is None:
                return input_text
            else:
                return to_return_val
    except Exception as e:
        if return_None:
            print('error happened, none returned. Error: {}'.format(e))
            return None
        else:
            print('error happened, input_text returned. Error: {}'.format(e))
            return input_text if to_return_val is None else to_return_val


ARGS = {
    "input_text": "```sql\nSELECT * FROM users WHERE id = 1\n```",
    "return_None": True,
    "output_of_gpt": True,
    "to_return_val": None,
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
none outside the standard library — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type str — a str output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a str output the recorded ndim 0 and dtype family float describe that coercion, not the output, and are not stated
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
timeout Ran
ran; our contract draft was wrong, not the code
microsoft/synqo/magic/multi_agent_feedback_generation.py
code served (permissive licence) · get_code("9a3da427295e86ae")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned function. The image it ran in was not recorded. If your copy returns the same type on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import torch
import functools
from threading import Thread

# Define a simple test function that we'll decorate
def simple_function(x, y):
    """A simple function that returns the sum of x and y"""
    return x + y

# Create the timeout decorator
def timeout(timeout_seconds):
    def deco(func):
        @functools.wraps(func)
        def wrapper(*args, **kwargs):
            res = [Exception('function [%s] timeout [%s seconds] exceeded!' % (func.__name__, timeout_seconds))]

            def newFunc():
                try:
                    res[0] = func(*args, **kwargs)
                except Exception as e:
                    res[0] = e
            t = Thread(target=newFunc)
            t.daemon = True
            try:
                t.start()
                t.join(timeout_seconds)
            except Exception as je:
                print('error starting thread')
                raise je
            ret = res[0]
            if isinstance(ret, BaseException):
                raise ret
            return ret
        return wrapper
    return deco

# Apply the timeout decorator to the test function
@timeout(5)
def decorated_function(x, y):
    return x + y

# Create arguments for the timeout function
# The timeout function takes one parameter: timeout (a number representing seconds)
ARGS = {
    'timeout': 5
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type function — a function output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a function output the recorded ndim 0 and dtype family float describe that coercion, not the output, and are not stated
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block

Also present in other papers' code

Of 3 samples lifted from this paper's linked repositories, 3 carry a function identity and 0 do not. Of the 3 distinct functions with an identity, 3 are also present in other papers whose code we hold (0 with at least one paper dated earlier, 0 the same month, 3 later) and 0 are only here among the 52,977 papers whose code Syntology holds (as of 2026-09-26).

Only here means: among the 52,977 papers whose code Syntology holds (51,887 with lifted samples, 1,090 through their assemblies only), as of 2026-09-26, no other paper's lifted samples or current assembly bricks contain an identical function body after normalisation.

FunctionAlso present inEarliest-datedOthers named
execute_query 1 other paper
1 later
aaai_34511 (2025 (year only))
MAGIC: Generating Self-Correction Guideline for In-Context Text-to-SQL
extract_sql_query 1 other paper
1 later
aaai_34511 (2025 (year only))
MAGIC: Generating Self-Correction Guideline for In-Context Text-to-SQL
timeout 1 other paper
1 later
aaai_34511 (2025 (year only))
MAGIC: Generating Self-Correction Guideline for In-Context Text-to-SQL

Presence, not direction: an identical function body in two papers' repositories does not say who wrote it, which came from which, or that either paper's method rests on it. Matching is exact after normalisation, so a renamed or edited function is not matched. Dates are when papers appeared, not when code was written. Only .py files the harvester lifted are covered; notebooks are not read. A new-style arXiv id YYMM.NNNN dates a paper to the month 20YY-MM; otherwise Paper.year dates it to the year; otherwise it is undated. Dates are when the paper appeared, not when the code was written. Read 2026-11-22.

Repositories linked to this paper

Some links come from the archived Papers with Code dataset (CC BY-SA 4.0): attribution and licence.

Abstract

Self-correction in text-to-SQL is the process of prompting large language model (LLM) to revise its previously incorrectly generated SQL, and commonly relies on manually crafted self-correction guidelines by human experts that are not only labor-intensive to produce but also limited by the human ability in identifying all potential error patterns in LLM responses. We introduce MAGIC, a novel multi-agent method that automates the creation of the self-correction guideline. MAGIC uses three specialized agents: a manager, a correction, and a feedback agent. These agents collaborate on the failures of an LLM-based method on the training set to iteratively generate and refine a self-correction guideline tailored to LLM mistakes, mirroring human processes but without human involvement. Our extensive experiments show that MAGIC's guideline outperforms expert human's created ones. We empirically find out that the guideline produced by MAGIC enhances the interpretability of the corrections made, providing insights in analyzing the reason behind the failures and successes of LLMs in self-correction. All agent interactions are publicly available at https://huggingface.co/datasets/microsoft/MAGIC.

For agents

The same record, over MCP at https://syntology.ai/mcp:

get_harvested_code_for_paper("2406.12692")
get_code_for_paper("2406.12692")
have("2406.12692")

The run record, dated, one paper per request, free:

curl https://syntology.ai/api/ran/2406.12692.json

A badge for a README (the split and the date, never a ratio):

[![Syntology run record](https://syntology.ai/api/ran/2406.12692.svg)](https://syntology.ai/paper/2406.12692)

Connect an agent — have() is free.