SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · aaai_29823 · AAAI · 2024

FlexKBQA: A Flexible LLM-Powered Framework for Few-Shot Knowledge Base Question Answering

Ning Liu, Jianyong Wang, Bowen Dong, Yu Gu, Zhenyu Li, Sunqi Fan, Zhichao Duan, Xiuxing Li

Open in the Atlas

Code that ran

7 of 10 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 3 have no contract verdict; 4 failures of our instrument; 3 no recorded run), measured 2026-11-24; 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/aaai_29823.json · badge: /api/ran/aaai_29823.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
leezythu/FlexKBQA canonical (classifier label)
classifier basis: census
7 ran · 3 no recorded run
FunctionStatusWhere it lives
convert_parse_instance Ran
ran on a synthesized input
leezythu/FlexKBQA/flexkbqa/automatic_program_sampling/parse_sparql.py
code served (permissive licence) · get_code("839e5ffd3c407e99")
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 tuple, ndim 1, 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 torch
import numpy as np

# Mock parser module with parse_query function
class MockParser:
    @staticmethod
    def parse_query(sparql, topic_entity_mid):
        # Returns a simple s-expression string with namespace prefix
        return "(AND (JOIN (R film.director) ns:m.0123) (R film.initial_release_date))"

parser = MockParser()

# Construct a valid parse instance
parse = {
    'sparql': 'SELECT ?x WHERE { ?x film:director ns:m.0123 . ?x film:initial_release_date ?date . }',
    'TopicEntityMid': 'ns:m.0123',
    'mid2name': {
        'ns:m.0123': 'Steven Spielberg',
        'ns:film.director': 'director',
        'ns:film.initial_release_date': 'release_date'
    }
}

ARGS = {
    'parse': parse
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
numpy, torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type tuple, ndim 1, dtype family float — a tuple 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
convert_parse_instance Ran
ran on a synthesized input
leezythu/FlexKBQA/flexkbqa/automatic_program_sampling/parse_sparql_grail.py
code served (permissive licence) · get_code("33d09c41fb52d8e1")
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 dict. 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 numpy as np

torch.manual_seed(0)

# Construct valid arguments for convert_parse_instance
data = {
    'vars': {
        'x': {
            'id': 'ns:m.0123456',
            'name': 'entity_name'
        },
        'y': {
            'id': 'ns:type.object.name',
            'name': 'ns:property_name'
        },
        'z': {
            'id': 'some_id',
            'name': 'ns:another_property'
        }
    }
}

sexpr_tem = '(AND ?x (type.object.name ?y) (some_relation ?z))'

ARGS = {
    'data': data,
    'sexpr_tem': sexpr_tem
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
numpy, torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type dict — a dict output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a dict 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
filter_valid_entities Ran
ran; our contract draft was wrong, not the code
leezythu/FlexKBQA/flexkbqa/automatic_program_sampling/step_wise_grounding.py
code served (permissive licence) · get_code("3962087375b033b3")
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 1, 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 torch

ARGS = {
    'results': {
        'results': {
            'bindings': [
                {
                    'entity1': {'value': 'http://example.com/m.entity1'},
                    'entity2': {'value': 'http://example.com/m.entity2'}
                },
                {
                    'entity1': {'value': 'http://example.com/m.entity3'},
                    'entity2': {'value': 'http://example.com/m.entity4'}
                },
                {
                    'entity1': {'value': 'http://example.com/m.entity5'},
                    'entity2': {'value': 'http://example.com/invalid'}
                }
            ]
        }
    }
}
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 list, ndim 1, 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
filter_valid_rels Ran
ran; our contract draft was wrong, not the code
leezythu/FlexKBQA/flexkbqa/automatic_program_sampling/step_wise_grounding.py
code served (permissive licence) · get_code("e5cc091247cb94e0")
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 1, 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 torch
import numpy as np

# Construct a valid results dict that matches the expected structure
# The function expects results['results']['bindings'] to be a list of dicts
# where each dict has keys with values containing a 'value' field that is a URL string

results = {
    'results': {
        'bindings': [
            {
                'rel1': {
                    'value': 'http://rdf.freebase.com/ns/people/person/name'
                },
                'rel2': {
                    'value': 'http://rdf.freebase.com/ns/film/film/directed_by'
                }
            },
            {
                'rel1': {
                    'value': 'http://rdf.freebase.com/ns/common/topic/description'
                },
                'rel2': {
                    'value': 'http://rdf.freebase.com/ns/type/object/name'
                }
            },
            {
                'rel1': {
                    'value': 'http://rdf.freebase.com/ns/music/artist/origin'
                },
                'rel2': {
                    'value': 'http://rdf.freebase.com/ns/base/schemastaging/person_extra/birth_name'
                }
            },
            {
                'rel1': {
                    'value': 'http://rdf.freebase.com/ns/film/actor/film'
                },
                'rel2': {
                    'value': 'http://www.w3.org/1999/02/22-rdf-syntax-ns#type'
                }
            },
            {
                'rel1': {
                    'value': 'http://rdf.freebase.com/ns/sports/sports_team/roster'
                },
                'rel2': {
                    'value': 'http://rdf.freebase.com/ns/music/genre/artists'
                }
            }
        ]
    }
}

ARGS = {
    'results': results
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
numpy, torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type list, ndim 1, 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
filter_valid_rets Ran
ran; our contract draft was wrong, not the code
leezythu/FlexKBQA/flexkbqa/automatic_program_sampling/step_wise_grounding.py
code served (permissive licence) · get_code("5d1c22509b7af5f6")
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 1, 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 torch
import numpy as np

# Test case 1: Results with valid entities (keys starting with 'm.')
results_entities = {
    'head': {
        'vars': ['entity1', 'entity2']
    },
    'results': {
        'bindings': [
            {
                'entity1': {'value': 'http://rdf.freebase.com/ns/m.0123456'},
                'entity2': {'value': 'http://rdf.freebase.com/ns/m.0789012'}
            },
            {
                'entity1': {'value': 'http://rdf.freebase.com/ns/m.0345678'},
                'entity2': {'value': 'http://rdf.freebase.com/ns/m.0567890'}
            }
        ]
    }
}

# Test case 2: Results with valid relations (contains 'ns' but not freebase/common/type/rdf/base/_id/.uri)
results_rels = {
    'head': {
        'vars': ['rel1', 'rel2']
    },
    'results': {
        'bindings': [
            {
                'rel1': {'value': 'http://rdf.freebase.com/ns/people/person/name'},
                'rel2': {'value': 'http://rdf.freebase.com/ns/location/location/area'}
            }
        ]
    }
}

# Test case 3: Mixed invalid results
results_invalid = {
    'head': {
        'vars': ['entity1']
    },
    'results': {
        'bindings': [
            {
                'entity1': {'value': 'http://example.com/invalid_entity'}
            }
        ]
    }
}

ARGS = {
    'results': results_entities
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
numpy, torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type list, ndim 1, 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
filter_valid_rets Ran
ran on a synthesized input
leezythu/FlexKBQA/flexkbqa/automatic_program_sampling/step_wise_grounding_grail.py
code served (permissive licence) · get_code("4c4fab724894dcab")
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 1, 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 torch

def filter_valid_rels(results):
    valid_results = []
    bindings = results['results']['bindings']
    for bind in bindings:
        flag = True
        for key in bind:
            rel = bind[key]['value'].split('/')[-1]
            if not 'ns' in bind[key]['value'].split('/') or 'freebase' in rel or 'common' in rel or ('type' in rel) or ('rdf' in rel) or ('base' in rel) or ('_id' in rel) or ('.uri' in rel):
                flag = False
        if flag:
            valid_results.append(bind)
    return valid_results

def filter_valid_rets(results):
    return filter_valid_rels(results)

ARGS = {
    'results': {
        'results': {
            'bindings': [
                {
                    'entity': {'value': 'http://ns.example.com/person/john'},
                    'property': {'value': 'http://ns.example.com/knows'}
                },
                {
                    'entity': {'value': 'http://ns.example.com/person/jane'},
                    'property': {'value': 'http://ns.example.com/worksAt'}
                }
            ]
        }
    }
}
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 list, ndim 1, 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
load_from_file Ran
ran; our contract draft was wrong, not the code
leezythu/FlexKBQA/flexkbqa/low_resource_program_translation/annotate_kb_program.py
code served (permissive licence) · get_code("938b97d3eeb7e5e1")
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 dict. 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 json
import tempfile
import os

# Create a temporary JSON file for testing
temp_dir = tempfile.mkdtemp()
test_data = {
    "key1": "value1",
    "key2": [1, 2, 3],
    "key3": {"nested": "data"}
}

# Write test data to a JSON file (without .json extension, as the function adds it)
test_file_path = os.path.join(temp_dir, "test_file")
with open(test_file_path + ".json", "w") as f:
    json.dump(test_data, f)

ARGS = {
    "path": test_file_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 dict — a dict output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a dict 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
attach_ent_name Not yet run
unverified (harvested, no recorded run)
leezythu/FlexKBQA/flexkbqa/low_resource_program_translation/annotate_kb_program_turbo_grail.py
code served (permissive licence) · get_code("914a43c3b4610905")
How it ran

no invocation recorded.

worker_annotate Not yet run
unverified (harvested, no recorded run)
leezythu/FlexKBQA/flexkbqa/low_resource_program_translation/annotate_kb_program_turbo.py
code served (permissive licence) · get_code("3f48da952ffd3919")
How it ran

no invocation recorded.

worker_annotate Not yet run
unverified (harvested, no recorded run)
leezythu/FlexKBQA/flexkbqa/low_resource_program_translation/annotate_kb_program_turbo_grail.py
code served (permissive licence) · get_code("b384183163093830")
How it ran

no invocation recorded.

Also present in other papers' code

Of 10 samples lifted from this paper's linked repositories, 10 carry a function identity and 0 do not. Of the 10 distinct functions with an identity, 4 are also present in other papers whose code we hold (4 with at least one paper dated earlier, 0 the same month, 0 later) and 6 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
filter_valid_entities 1 other paper
1 dated earlier
2308.12060 (2023-08)
FlexKBQA: A Flexible LLM-Powered Framework for Few-Shot Knowledge Base Question Answering
filter_valid_rels 1 other paper
1 dated earlier
2308.12060 (2023-08)
FlexKBQA: A Flexible LLM-Powered Framework for Few-Shot Knowledge Base Question Answering
filter_valid_rets 1 other paper
1 dated earlier
2308.12060 (2023-08)
FlexKBQA: A Flexible LLM-Powered Framework for Few-Shot Knowledge Base Question Answering
load_from_file 1 other paper
1 dated earlier
2308.12060 (2023-08)
FlexKBQA: A Flexible LLM-Powered Framework for Few-Shot Knowledge Base Question Answering

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-24.

Repositories linked to this paper

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

Abstract

Knowledge base question answering (KBQA) is a critical yet challenging task due to the vast number of entities within knowledge bases and the diversity of natural language questions posed by users. Unfortunately, the performance of most KBQA models tends to decline significantly in real-world scenarios where high-quality annotated data is insufficient. To mitigate the burden associated with manual annotation, we introduce FlexKBQA by utilizing Large Language Models (LLMs) as program translators for addressing the challenges inherent in the few-shot KBQA task. Specifically, FlexKBQA leverages automated algorithms to sample diverse programs, such as SPARQL queries, from the knowledge base, which are subsequently converted into natural language questions via LLMs. This synthetic dataset facilitates training a specialized lightweight model for the KB. Additionally, to reduce the barriers of distribution shift between synthetic data and real user questions, FlexKBQA introduces an execution-guided self-training method to iterative leverage unlabeled user questions. Furthermore, we explore harnessing the inherent reasoning capability of LLMs to enhance the entire framework. Consequently, FlexKBQA delivers substantial flexibility, encompassing data annotation, deployment, and being domain agnostic. Through extensive experiments on GrailQA, We-bQSP, and KQA Pro, we observe that under the few-shot even more challenging zero-shot scenarios, FlexKBQA achieves impressive results with a few annotations, surpassing all previous baselines and even approaching the performance of supervised models, achieving a remarkable 93% performance relative to the fully-supervised models. We posit that FlexK-BQA represents a significant advancement towards exploring better integration of large and lightweight models. Code is available at https://github.com/leezythu/FlexKBQA.

For agents

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

get_harvested_code_for_paper("aaai_29823")
get_code_for_paper("aaai_29823")
have("aaai_29823")

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

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

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

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

Connect an agent — have() is free.