Bridging Large Language Models and Logic Programming

Authors:

Abstract
This paper introduces a self-correcting framework11The source code is available at: https://github.com/Pryce22/LLM-Prolog that converts natural language queries into executable Prolog code. The core of our approach is an iterative refinement loop that leverages structured error feedback from the SWI-Prolog engine. A key feature is our dynamic temperature scheduling mechanism, where the LLM's temperature is incrementally increased upon each failed attempt. This injection of adaptive stochasticity forces the model to escape deterministic failure modes and explore a wider solution space. By tightly integrating Prolog's logic, the system produces formally verifiable outputs, enhancing reasoning reliability in logically complex scenarios. Experimental results demonstrate the framework's value as a “logical guardrail”. Although a base LLM may achieve higher average accuracy, our method excels in enhancing reliability where formal reasoning is critical. This is highlighted by its ability to recover correct solutions for a significant portion of the cases (9 out of 24) on which a powerful 72B parameter base model failed, showcasing its utility in applications demanding precision and consistency. The system is deployed in a chat interface, lowering barriers for non-experts while improving productivity for experts using logic programming. Its modular, adaptive design establishes a foundation for combining symbolic reasoning with LLMs, supporting the development of more trustworthy AI systems.

This publication has 3 references indexed in Scilit: