Learning and Enforcing Context-Sensitive Control for LLMs
Mohammad Albinhassan, Pranava Madhyastha, Mark Law, Alessandra Russo
Abstract
Controlling the output of Large Language Models (LLMs) through context-sensitive constraints has emerged as a promising approach to overcome the limitations of Context-Free Grammars (CFGs) in guaranteeing generation validity. However, such constraints typically require manual specification—a significant barrier demanding specialized expertise. We introduce a framework that automatically learns context-sensitive constraints from LLM interactions through a two-phase process: syntactic exploration to gather diverse outputs for constraint learning, followed by constraint exploitation to enforce these learned rules during generation. Experiments demonstrate that our method enables even small LLMs (1B parameters) to learn and generate with perfect constraint adherence, outperforming larger counterparts and state-of-the-art reasoning models. This work represents the first integration of context-sensitive grammar learning with LLM generation, eliminating manual specification while maintaining generation validity.- Anthology ID:
- 2025.acl-srw.59
- Volume:
- Proceedings of the 63rd Annual Meeting of the Association for Computational Linguistics (Volume 4: Student Research Workshop)
- Month:
- July
- Year:
- 2025
- Address:
- Vienna, Austria
- Editors:
- Jin Zhao, Mingyang Wang, Zhu Liu
- Venues:
- ACL | WS
- SIG:
- Publisher:
- Association for Computational Linguistics
- Note:
- Pages:
- 834–842
- Language:
- URL:
- https://preview.aclanthology.org/landing_page/2025.acl-srw.59/
- DOI:
- Cite (ACL):
- Mohammad Albinhassan, Pranava Madhyastha, Mark Law, and Alessandra Russo. 2025. Learning and Enforcing Context-Sensitive Control for LLMs. In Proceedings of the 63rd Annual Meeting of the Association for Computational Linguistics (Volume 4: Student Research Workshop), pages 834–842, Vienna, Austria. Association for Computational Linguistics.
- Cite (Informal):
- Learning and Enforcing Context-Sensitive Control for LLMs (Albinhassan et al., ACL 2025)
- PDF:
- https://preview.aclanthology.org/landing_page/2025.acl-srw.59.pdf