Hostname: page-component-76d6cb85b7-ntvhh Total loading time: 0 Render date: 2026-07-18T13:03:48.668Z Has data issue: false hasContentIssue false

Logic-Guided Data Extraction with Answer Set Programming and Large Language Models

Published online by Cambridge University Press:  08 July 2026

MARIO ALVIANO
Affiliation:
Department of Mathematics and Computer Science, University of Calabria, Italy (e-mail: mario.alviano@unical.it)
LORENZO GRILLO
Affiliation:
Università degli Studi della Campania Luigi Vanvitelli, Italy (e-mail: lorenzo.grillo@unicampania.it)
NICOLA LEONE
Affiliation:
Department of Mathematics and Computer Science, University of Calabria, Italy (e-mail: nicola.leone@unical.it)
FABRIZIO LO SCUDO
Affiliation:
Department of Mathematics and Computer Science, University of Calabria, Italy (e-mail: fabrizio.loscudo@unical.it)
Rights & Permissions [Opens in a new window]

Abstract

When large language models (LLMs) are used for semantic data extraction from unstructured text, producing candidate relational facts from natural language, they may remain unreliable for tasks requiring complex combinatorial reasoning and global consistency. This paper proposes a logic-guided data extraction framework combining LLM-based extraction with answer set programming (ASP). The LLM produces candidate facts, whereas ASP performs validation, inference, consistency checking, and control. Unlike existing pipelines that query the LLM independently for all target predicates, the proposed approach uses ASP reasoning to identify which predicates are logically admissible at each stage and to guide extraction queries. By interleaving LLM calls with ASP derivation, the framework infers logically implied facts without further extraction and detects inconsistencies early. We formalize the pipeline and prove that, under mild assumptions, it is equivalent to the baseline approach with respect to the final extracted facts, while requiring fewer LLM calls. We also introduce a caching mechanism for logic-based control queries, exploiting monotonicity of conjunctive queries over incrementally constructed fact sets to reduce solver invocations. Experiments on ASP-derived benchmarks show that the framework reduces LLM calls and improves extraction quality by mitigating spurious outputs, demonstrating the value of non-monotonic logic programming for controlled semantic extraction.

Information

Type
Original Article
Creative Commons
Creative Common License - CCCreative Common License - BY
This is an Open Access article, distributed under the terms of the Creative Commons Attribution licence (https://creativecommons.org/licenses/by/4.0/), which permits unrestricted re-use, distribution and reproduction, provided the original article is properly cited.
Copyright
© The Author(s), 2026. Published by Cambridge University Press
Figure 0

Figure 1. Comparison of a three-layer graph before (left) and after (right) applying a crossing minimization strategy. Intersecting edges are highlighted in red. Reordering the nodes, specifically in Layer 2, significantly reduces the total number of crossings and improves the readability of the layout.

Figure 1

Algorithm 1 LGX-Exec(T, D0,C): Logic-guided extraction with guard caching

Figure 2

Table 1. Experimental results on Graph (G) and Logic Puzzle (LNRS) benchmarks. We report the number of Oracle interactions (O$\mathscr{O}$ Calls), the enforcement strategy, and accuracy metrics (F1-Score, Perfect Rate)