potentialpaper

ConstrainPrompt: Code-Based Assurance of Prompt-Defined Constraints

Yuetian Mao, Chunyang Chen

ICLR 2026 submission

Edit this page

Or clone it with git

The page gets its repository with its first edit, so start in the web editor.

Or let your agent set it up

It checks and sets up everything: signing in, git, the clone, credentials and an SSH key.

Abstract. Large language models (LLMs) are increasingly used in applications where outputs must satisfy hard, application–critical constraints (e.g., JSON format, lexical inclusion, and length limits). When these constraints are violated, downstream parsers may fail (e.g., invalid JSON), application behavior can become incorrect or unsafe (e.g., missing required strings or forbidden terms), and automation pipelines may halt. Although controlled text generation can mitigate violations, LLM outputs still frequently breach constraints. Therefore, post-generation evaluation is essential. Common evaluators implemented by LLM-as-a-judge or rule-based scripts under-penalize hard errors and lack robust, fine-grained evaluation control flow. We propose ConstrainPrompt, a verification pipeline that induces semantics-agnostic, code-verifiable constraints from natural-language prompts and compiles them into executable validators. Our method extracts code-verifiable constraints from the prompt, synthesizes a logical evaluation tree that orders global-to-local checks and resolves conditional guards, and finally generates code to validate LLM outputs. On a corpus of real-world prompts paired with LLM outputs, ConstrainPrompt improves Constraint Compliance Accuracy by 24.3% and Violation Rationale by 40.8% over an LLM-as-a-judge baseline across three models.

Are you an author? Claim this paper to see who's reading it, with views and other statistics, and to write about it here.

Claim this paper
How does this paper connect to your work? Write how you built on it, compared with it or reproduced it, or add a summary, a critique or errata.
Or make it interactive:
Start writing

add · history

No versions are recorded yet: its preprint, the venues it went to and what they decided, the camera-ready. Missing a version?

We don't know of a submission of this paper to a venue with open reviews. Missing a submission?

Loading the discussion…