Natural Language Knowledge Graph Query Execution: Leveraging Controlled Semantics in the LLM Context Window
Organizations: Max Planck Institute for Biological Cybernetics, Tübingen, Germany
Abstract
Large Language Model (LLM) applications often transfer domain concepts into the model's context informally, through prompt prose, schema dumps, and examples. We show that for database queries, data model concepts pass to LLMs more effectively through representations whose vocabulary terms carry declared, machine-readable semantics (controlled semantics). NLKGQ is a working system and reusable framework that does this for data modeled in a knowledge graph. A formal OWL ontology serves as the transfer mechanism, concentrating the meaning of the data into semantically precise tokens the model can use directly. In a single LLM call, NLKGQ places in the context a system prompt instructing on SPARQL, the complete domain OWL ontology, and a domain-specific prompt addition, together with the user's natural language query. The model then generates the SPARQL query directly, zero-shot. Where the native vocabulary of an existing database or federation of databases is opaque, a wrapper ontology substitutes clean terms and a runtime rewriter restores the native forms. Evaluating on DBLP-QuAD 2.0 showed that its scores depend on the graph snapshot, the endpoint used, and the wording of its machine-generated questions, so we propose DBLP-QuAD 3.1, which maintains the intent of 2.0 while making reference results deterministic, revising reference SPARQL where needed, and rewriting the natural language questions, with a frontier model, to state each reference query's intent clearly and completely. We evaluate on the DBLP-QuAD 2.0 benchmark (57.6% Match under deterministic re-scoring), DBLP-QuAD 3.1 (89.9% Match on 1,000 questions), SemOpenAlex (98% Match against a published baseline's 86% on the identical test set), and neuroimaging metadata (100%).
Figures & tables
| Metric | Scoring | Criterion |
|---|---|---|
| Match | binary | generated results contain the reference results, equal or superset |
| Exact | binary | generated results have an exact match to reference results |
| QuAD F1 | graded | set-of-values F1 over all result cells, flattened as in QuAD 2.0’s evaluation code ( Taffa et al. 2025 ) |
| SPINACH F1 | graded | row-assignment F1 of Liu et al. (2024) , implemented following the published code of GRASP ( Walter and Bast 2025 ) |
| QuAD | Ontology | Match | Exact | QuAD F1 | SPINACH F1 |
|---|---|---|---|---|---|
| 2.0 | native | 43.0 | 10.7 | 23.2 | 23.0 |
| 2.0 | wrapper | 52.9 | 11.3 | 17.6 | 17.5 |
| 2.1 | wrapper | 57.6 | 20.1 | 16.7 | 17.3 |
| 3.1 | native | 74.9 | 56.0 | 63.8 | 62.3 |
| 3.1 | wrapper | 89.9 | 81.3 | 80.7 | 79.0 |
| Domain | Cases | Match% | Exact% | F1 S | Baseline |
|---|---|---|---|---|---|
| DBLP (QuAD 3.1) | 1,000 | 89.9 | 81.3 | 79.0 | 51.0 F1 |
| SemOpenAlex | 100 | 98.0 | 98.0 | — | 86/100 |
| Neuroimaging | 21 | 100.0 | 100.0 | — | — |
| Model | Type | Match | Exact | F1 Q | F1 S | Fail |
|---|---|---|---|---|---|---|
| Gemma-4-31B | dense | 90.3 | 75.1 | 79.4 | 76.9 | 3.5 |
| Qwen3.6-27B-FP8 | dense/q | 90.0 | 81.4 | 81.3 | 79.4 | 2.5 |
| Qwen3.6-27B | dense | 89.9 | 81.4 | 80.8 | 79.1 | 3.4 |
| Qwen3-Coder-30B | MoE/code | 81.1 | 62.3 | 69.6 | 67.9 | 4.0 |
| Mistral-Small-24B | dense | 80.6 | 65.2 | 68.0 | 64.3 | 4.7 |
| Llama3.3-70B | dense | 74.3 | 59.4 | 63.6 | 61.7 | 5.0 |
Knowledge Graph Question Answering
Knowledge Graph Question Answering answers natural-language questions by finding and reasoning over entities and relations in structured knowledge graphs.
See all 165 papers