---
title: "Training Language Models to Use Prolog as a Tool (2026)"
description: "The authors investigate whether a small model can learn, through reinforcement learning, to offload… 20 references, cited by 1 paper here."
authors: ["Niklas Mellgren", "Peter Schneider-Kamp", "Lukas Galke Poech"]
year: 2026
venue: "Findings of the Association for Computational Linguistics: ACL 2026"
source: "https://aclanthology.org/2026.findings-acl.1644/"
doi: "10.18653/v1/2026.findings-acl.1644"
licence: "CC BY 4.0 (ACL Anthology)"
licence_url: "https://creativecommons.org/licenses/by/4.0/"
summary_licence: "Elamur Cosmic License"
canonical: "https://research.elamur.ai/free/en/papers/mellgren-2026-training-language-models-use-prolog/"
---
[Elamur Research](https://md.research.elamur.ai/free/en/) · [this page in HTML](https://research.elamur.ai/free/en/papers/mellgren-2026-training-language-models-use-prolog/)

[home](https://md.research.elamur.ai/free/en/) / [papers](https://md.research.elamur.ai/free/en/papers/) / [2026](https://md.research.elamur.ai/free/en/papers/2026/page/18/) / Training Language Models to Use Prolog as a Tool

# Training Language Models to Use Prolog as a Tool

**Authors:** Niklas Mellgren, [Peter Schneider-Kamp](https://md.research.elamur.ai/free/en/authors/peter-schneider-kamp/) and [Lukas Galke Poech](https://md.research.elamur.ai/free/en/authors/lukas-galke-poech/) · **Year:** 2026 · **Venue:** [Findings of the Association for Computational Linguistics: ACL 2026](https://md.research.elamur.ai/free/en/venues/findings/) ([Findings of the Association for Computational Linguistics 2026](https://md.research.elamur.ai/free/en/venues/findings/2026/)) · **Publisher:** [Association for Computational Linguistics](https://md.research.elamur.ai/free/en/publishers/association-for-computational-linguistics/) · **Licence:** [CC BY 4.0 (ACL Anthology)](https://creativecommons.org/licenses/by/4.0/)

**Links:** [Publisher's page](https://aclanthology.org/2026.findings-acl.1644/) · [PDF](https://aclanthology.org/2026.findings-acl.1644.pdf) · [DOI 10.18653/v1/2026.findings-acl.1644](https://doi.org/10.18653/v1/2026.findings-acl.1644) · [OpenAlex](https://openalex.org/W7166840358)

**Citations:** 0 citations (OpenAlex, 2026-10-14) · 1 in our library, of the 149,439 papers whose bibliographies we read

## Summary
Language models often produce reasoning that sounds convincing but is wrong and hard to check. The authors investigate whether a small model can learn, through reinforcement learning, to offload reasoning to Prolog, whose logical derivations are explicit and inspectable. They fine-tune Qwen2.5-3B-Instruct with GRPO on a cleaned GSM8K variant, released as gsm8k-prolog-prover. Programs are executed in SWI-Prolog. The study varies three factors: four system prompts, three reward suites (combining execution, syntax, semantic and structural signals), and several inference protocols, from single-try to agentic self-repair.

GRPO beats a supervised fine-tuning baseline on GSM8K. With agentic inference, the 3B model's zero-shot scores on MMLU-STEM and MMLU-Pro are comparable to few-shot 7B models. The central finding is a tension between accuracy and auditability. When rewarded only for correct answers, the model reasons in natural language and uses Prolog merely to compute the final result, which the authors classify as reward hacking. Rewarding symbolic structure produces fully auditable programs but lowers accuracy. This matters for neurosymbolic systems in high-stakes fields such as medicine and law.

## Key points
- **Setup:** Qwen2.5-3B-Instruct, trained with GRPO, using SWI-Prolog as the execution engine. The cleaned training set is published as gsm8k-prolog-prover, and the code is in the aisilab/Prolog-as-a-Tool repository.
- **System prompts:** SP-Base, SP-Struct, SP-Declare (every numeric constant must be a named predicate) and SP-Reflect (adds self-review before emitting code).
- **Reward suites:**
  - Rwd1 covers correctness, syntax and format.
  - Rwd2 adds Sentence-BERT similarity and predicate-name overlap.
  - Rwd3 adds curriculum weighting and a penalty for hard-coded answers.
- **Inference protocols:**
  - Multiple-try with external verification gives the best in-distribution accuracy.
  - Agentic-Internal, which keeps debugging context, generalizes best to MMLU and performs best on the full GSM8K test set.
- **Error analysis:**
  - SP-Struct with Rwd1 reaches about 90% execution accuracy but produces structurally weak programs.
  - The Declare variants give 31–36% wrong answers.
  - Most failures are missing code extraction, followed by uninstantiated variables.

*Our summary of the paper, in our own words — not its text. The work belongs to its authors; read it at the links above.*

📚 Shelves (4): [🖥️ Computer Science](https://md.research.elamur.ai/free/en/shelves/computer-science/) · 16,667 works · [🤖 Artificial Intelligence](https://md.research.elamur.ai/free/en/shelves/computer-science/artificial-intelligence/) · 16,194 works · [🎭 Arts and Humanities](https://md.research.elamur.ai/free/en/shelves/arts-and-humanities/) · 16,039 works · [🗣️ Language and Linguistics](https://md.research.elamur.ai/free/en/shelves/arts-and-humanities/language-and-linguistics/) · 15,891 works

🧭 Topics (1): [🧠 Language models & pretraining](https://md.research.elamur.ai/free/en/topics/language-models/) · 3,320 works

## Cite

Cite as: Niklas Mellgren, Peter Schneider-Kamp and Lukas Galke Poech. 2026. Training Language Models to Use Prolog as a Tool. Findings of the Association for Computational Linguistics: ACL 2026.

The paper itself, not this page. BibTeX from the library's record of the work.

```bibtex
@inproceedings{mellgren2026training,
  title = {{Training Language Models to Use Prolog as a Tool}},
  author = {Niklas Mellgren, Peter Schneider-Kamp and Lukas Galke Poech},
  booktitle = {Findings of the Association for Computational Linguistics: ACL 2026},
  year = {2026},
  doi = {10.18653/v1/2026.findings-acl.1644},
  url = {https://doi.org/10.18653/v1/2026.findings-acl.1644}
}
```

- [← previous Tracing Multilingual Knowledge Acquisition Dynamics in Domain Adaptation: A Case Study of Biomedical Adaptation](https://md.research.elamur.ai/free/en/papers/zhao-2026-tracing-multilingual-knowledge-acquisition-dynamics/)
- [next → Trajectory Signatures of Deception in Large Language Models](https://md.research.elamur.ai/free/en/papers/mothukuri-2026-trajectory-signatures-deception-large-language/)
- [↑ back to papers of 2026](https://md.research.elamur.ai/free/en/papers/2026/page/18/)

## References

20 references, 9 of them with a card of ours. ↗ leads to the work, «find» searches for one we have no id for yet.

1. Samy Bengio, Oriol Vinyals, Navdeep Jaitly, and Noam Shazeer. 2015. Scheduled sampling for sequence prediction with recurrent neural networks. In NeurIPS, pages 1171–1179. [find](https://scholar.google.com/scholar?q=Samy+Bengio%2C+Oriol+Vinyals%2C+Navdeep+Jaitly%2C+and+Noam+Shazeer%2E+2015%2E+Scheduled+sampling+for+sequence+prediction+with+recurrent+neural+networks%2E+In+NeurIPS%2C+pages+1171%E2%80%931179%2E)
2. Jan Betley, Niels Warncke, Anna Sztyber-Betley, Daniel Tan, Xuchan Bao, Martín Soto, Megha Srivastava, Nathan Labenz, and Owain Evans. 2026. Training large language models on narrow tasks can lead to broad misalignment. Nat., 649(8097):584–589. [find](https://scholar.google.com/scholar?q=Jan+Betley%2C+Niels+Warncke%2C+Anna+Sztyber%2DBetley%2C+Daniel+Tan%2C+Xuchan+Bao%2C+Mart%C3%ADn+Soto%2C+Megha+Srivastava%2C+Nathan+Labenz%2C+and+Owain+Evans%2E+2026%2E+Training+large+language+models+on+narrow+tasks+can+lead+to+)
3. Eli Bingham, Jonathan P. Chen, Martin Jankowiak, Fritz Obermeyer, Neeraj Pradhan, Theofanis Karaletsos, Rohit Singh, Paul A. Szerlip, Paul Horsfall, and Noah D. Goodman. 2019. Pyro: Deep universal probabilistic programming. J. Mach. Learn. Res., 20:28:1–28:6. [find](https://scholar.google.com/scholar?q=Eli+Bingham%2C+Jonathan+P%2E+Chen%2C+Martin+Jankowiak%2C+Fritz+Obermeyer%2C+Neeraj+Pradhan%2C+Theofanis+Karaletsos%2C+Rohit+Singh%2C+Paul+A%2E+Szerlip%2C+Paul+Horsfall%2C+and+Noah+D%2E+Goodman%2E+2019%2E+Pyro%3A+Deep+universal+pro)
4. Nasim Borazjanizadeh and Steven Piantadosi. 2024. Reliable reasoning beyond natural language. Preprint, arXiv:2407.11373. — [arXiv:2407.11373](https://arxiv.org/abs/2407.11373) [find](https://scholar.google.com/scholar?q=Nasim+Borazjanizadeh+and+Steven+Piantadosi%2E+2024%2E+Reliable+reasoning+beyond+natural+language%2E+Preprint%2C+arXiv%3A2407%2E11373%2E+%E2%80%94+%5BarXiv%3A2407%2E11373%5D%28https%3A%2F%2Farxiv%2Eorg%2Fabs%2F2407%2E11373%29)
5. Tianzhe Chu, Yuexiang Zhai, Jihan Yang, Shengbang Tong, Saining Xie, Dale Schuurmans, Quoc V. Le, Sergey Levine, and Yi Ma. 2025. [SFT memorizes, RL generalizes: A comparative study of foundation model post-training](https://md.research.elamur.ai/free/en/papers/chu-2025-sft-memorizes-rl-generalizes-comparative/). In ICML, Proceedings of Machine Learning Research. PMLR / OpenReview.net.
6. Daya Guo, Dejian Yang, Haowei Zhang, Junxiao Song, Peiyi Wang, Qihao Zhu, Runxin Xu, Ruoyu Zhang, Shirong Ma, Xiao Bi, Xiaokang Zhang, Xingkai Yu, Yu Wu, Z. F. Wu, Zhibin Gou, Zhihong Shao, Zhuoshu Li, Ziyi Gao, Aixin Liu, and 175 others. 2025. Deepseek-R1 incentivizes reasoning in LLMs through rein… [find](https://scholar.google.com/scholar?q=Daya+Guo%2C+Dejian+Yang%2C+Haowei+Zhang%2C+Junxiao+Song%2C+Peiyi+Wang%2C+Qihao+Zhu%2C+Runxin+Xu%2C+Ruoyu+Zhang%2C+Shirong+Ma%2C+Xiao+Bi%2C+Xiaokang+Zhang%2C+Xingkai+Yu%2C+Yu+Wu%2C+Z%2E+F%2E+Wu%2C+Zhibin+Gou%2C+Zhihong+Shao%2C+Zhuoshu+Li)
7. Dan Hendrycks, Collin Burns, Steven Basart, Andy Zou, Mantas Mazeika, Dawn Song, and Jacob Steinhardt. 2021. [Measuring massive multitask language understanding](https://md.research.elamur.ai/free/en/papers/hendrycks-2020-measuring-massive-multitask-language-understanding/). In ICLR. OpenReview.net.
8. Edward J Hu, Yelong Shen, Phillip Wallis, Zeyuan Allen-Zhu, Yuanzhi Li, Shean Wang, Lu Wang, and Weizhu Chen. 2022. [LoRA: Low-rank adaptation of large language models](https://md.research.elamur.ai/free/en/papers/hu-2021-lora-low-rank-adaptation-large/). In ICLR. OpenReview.net.
9. Tomek Korbak, Mikita Balesni, Elizabeth Barnes, Yoshua Bengio, Joe Benton, Joseph Bloom, Mark Chen, Alan Cooney, Allan Dafoe, Anca Dragan, Scott Emmons, Owain Evans, David Farhi, Ryan Greenblatt, Dan Hendrycks, Marius Hobbhahn, Evan Hubinger, Geoffrey Irving, Erik Jenner, and 22 others. 2025. Chain… [find](https://scholar.google.com/scholar?q=Tomek+Korbak%2C+Mikita+Balesni%2C+Elizabeth+Barnes%2C+Yoshua+Bengio%2C+Joe+Benton%2C+Joseph+Bloom%2C+Mark+Chen%2C+Alan+Cooney%2C+Allan+Dafoe%2C+Anca+Dragan%2C+Scott+Emmons%2C+Owain+Evans%2C+David+Farhi%2C+Ryan+Greenblatt%2C+Dan+)
10. Tamera Lanham, Anna Chen, Ansh Radhakrishnan, Benoit Steiner, Carson Denison, Danny Hernandez, Dustin Li, Esin Durmus, Evan Hubinger, Jackson Kernion, and 1 others. 2023. [Measuring faithfulness in chain-of-thought reasoning](https://md.research.elamur.ai/free/en/papers/lanham-2023-measuring-faithfulness-chain-thought-reasoning/). Preprint, arXiv:2307.13702.
11. Monte MacDiarmid, Benjamin Wright, Jonathan Uesato, Joe Benton, Jonathan Kutasov, Sara Price, Naia Bouscal, Samuel R. Bowman, Trenton Bricken, Alex Cloud, Carson Denison, Johannes Gasteiger, Ryan Greenblatt, Jan Leike, Jack Lindsey, Vladimir Mikulik, Ethan Perez, Alex Rodrigues, Drake Thomas, and 3… — [arXiv:2511.18397](https://arxiv.org/abs/2511.18397) [find](https://scholar.google.com/scholar?q=Monte+MacDiarmid%2C+Benjamin+Wright%2C+Jonathan+Uesato%2C+Joe+Benton%2C+Jonathan+Kutasov%2C+Sara+Price%2C+Naia+Bouscal%2C+Samuel+R%2E+Bowman%2C+Trenton+Bricken%2C+Alex+Cloud%2C+Carson+Denison%2C+Johannes+Gasteiger%2C+Ryan+Gree)
12. Niklas Muennighoff, Zitong Yang, Weijia Shi, Xiang Lisa Li, Li Fei-Fei, Hannaneh Hajishirzi, Luke Zettlemoyer, Percy Liang, Emmanuel Candès, and Tatsunori Hashimoto. 2025. [s1: Simple test-time scaling](https://md.research.elamur.ai/free/en/papers/muennighoff-2025-s1-simple-test-time-scaling/). In EMNLP, pages 20275–20321.
13. OpenAI. 2024. [OpenAI o1 system card](https://md.research.elamur.ai/free/en/papers/openai-2024-openai-o1-system-card/). Preprint, arXiv:2412.16720.
14. Razvan Pascanu, Tomás Mikolov, and Yoshua Bengio. 2013. On the difficulty of training recurrent neural networks. In ICML, pages 1310–1318. JMLR.org. [find](https://scholar.google.com/scholar?q=Razvan+Pascanu%2C+Tom%C3%A1s+Mikolov%2C+and+Yoshua+Bengio%2E+2013%2E+On+the+difficulty+of+training+recurrent+neural+networks%2E+In+ICML%2C+pages+1310%E2%80%931318%2E+JMLR%2Eorg%2E)
15. An Yang, Baosong Yang, Beichen Zhang, Binyuan Hui, Bo Zheng, Bowen Yu, Chengyuan Li, Dayiheng Liu, Fei Huang, Haoran Wei, Huan Lin, Jian Yang, Jianhong Tu, Jianwei Zhang, Jianxin Yang, Jiaxi Yang, Jingren Zhou, Junyang Lin, Kai Dang, and 22 others. 2024a. Qwen2.5 technical report. Preprint, arXiv:24… [find](https://scholar.google.com/scholar?q=An+Yang%2C+Baosong+Yang%2C+Beichen+Zhang%2C+Binyuan+Hui%2C+Bo+Zheng%2C+Bowen+Yu%2C+Chengyuan+Li%2C+Dayiheng+Liu%2C+Fei+Huang%2C+Haoran+Wei%2C+Huan+Lin%2C+Jian+Yang%2C+Jianhong+Tu%2C+Jianwei+Zhang%2C+Jianxin+Yang%2C+Jiaxi+Yang%2C+Jin)
16. Debjit Paul, Robert West, Antoine Bosselut, and Boi Faltings. 2024. [Making reasoning matter: Measuring and improving faithfulness of chain-of-thought reasoning](https://md.research.elamur.ai/free/en/papers/paul-2024-making-reasoning-matter-measuring-improving/). In EMNLP Findings, pages 15012–15032.
17. Xiaocheng Yang, Bingsen Chen, and Yik-Cheung Tam. 2024b. Arithmetic reasoning with LLM: Prolog generation & permutation. In Proceedings of the 2024 Conference of the North American Chapter of the Association for Computational Linguistics: Human Language Technologies (Volume 2: Short Papers), pages 6… [find](https://scholar.google.com/scholar?q=Xiaocheng+Yang%2C+Bingsen+Chen%2C+and+Yik%2DCheung+Tam%2E+2024b%2E+Arithmetic+reasoning+with+LLM%3A+Prolog+generation+%26+permutation%2E+In+Proceedings+of+the+2024+Conference+of+the+North+American+Chapter+of+the+Asso)
18. Federico Pennino, Bianca Raimondi, Massimo Rondelli, Andrea Gurioli, and Maurizio Gabbrielli. 2025. From reasoning to code: GRPO optimization for underrepresented languages. Preprint, arXiv:2506.11027. — [arXiv:2506.11027](https://arxiv.org/abs/2506.11027) [find](https://scholar.google.com/scholar?q=Federico+Pennino%2C+Bianca+Raimondi%2C+Massimo+Rondelli%2C+Andrea+Gurioli%2C+and+Maurizio+Gabbrielli%2E+2025%2E+From+reasoning+to+code%3A+GRPO+optimization+for+underrepresented+languages%2E+Preprint%2C+arXiv%3A2506%2E11027)
19. Shunyu Yao, Jeffrey Zhao, Dian Yu, Nan Du, Izhak Shafran, Karthik Narasimhan, and Yuan Cao. 2023. [ReAct: Synergizing reasoning and acting in language models](https://md.research.elamur.ai/free/en/papers/yao-2022-react-synergizing-reasoning-acting-language/). In ICLR. OpenReview.net.
20. Timo Schick, Jane Dwivedi-Yu, Roberto Dessì, Roberta Raileanu, Maria Lomeli, Eric Hambro, Luke Zettlemoyer, Nicola Cancedda, and Thomas Scialom. 2023. [Toolformer: Language models can teach themselves to use tools](https://md.research.elamur.ai/free/en/papers/schick-2023-toolformer-language-models-can-teach/). In NeurIPS.

*Updated 31 October 2026*
