Scientific Knowledge-driven Decoding Constraints Improving the Reliability of LLMs

Maotian Ma, Zheni Zeng, Zhenghao Liu, Yukun YanarXiv 2026 · arXiv

TL;DR

The authors introduce SciDC (Scientific Knowledge-driven Decoding Constraints), a framework that forces large language models (LLMs) to strictly adhere to scientific rules and domain knowledge during text generation. By compiling natural language guidelines into a multi-layered constraint system—spanning structural, logical, and token-level rules—SciDC eliminates hallucinations and delivers an average 12% accuracy boost across complex tasks like clinical tumor diagnosis and chemical formulation design.

What Problem Does This Paper Address?

While LLMs possess massive knowledge reserves, they are fundamentally data-driven next-token predictors. This makes them prone to hallucinations that violate basic physical laws, chemical constraints, or medical guidelines. In high-stakes scientific domains, a single logical mismatch can render an AI's output useless or dangerous.

Existing solutions generally fall into two camps: prompt-based methods (which rely on the model to voluntarily follow instructions) and fine-tuning (which implicitly bakes knowledge into weights). Neither approach guarantees absolute logical or physical correctness. The authors address this gap by embedding hard scientific constraints directly into the LLM's decoding loop.

Figure 1: Examples of how general strong LLMs and domain models sometimes fail in specialized tasks.

Methods

SciDC introduces a collaborative, two-model architecture that splits the labor between a powerful General LLM (GLLM) and a smaller, locally deployable Domain LLM (DLLM):

  1. Standardized Rule Transformation: A strong GLLM (like Claude 3.5 Sonnet) acts as a "knowledge compiler," translating flexible natural language textbooks or guidelines into standardized, executable Python code.
  2. Multi-Layered Decoding Constraints: This executable code enforces constraints on the DLLM at three distinct granularities during generation:
  3. Top-Layer Rules ($R_T$): Structure-level constraints that mandate a specific step-by-step reasoning workflow (e.g., forcing the model to extract tumor size before attempting a diagnosis).
  4. Middle-Layer Rules ($R_M$): Logic-level constraints that perform conditional checks across generated segments. If a logical contradiction is detected, the framework triggers local backtracking and forces the model to regenerate that specific segment.
  5. Bottom-Layer Rules ($R_B$): Token-level constraints that directly modify the decoder logits via masking, ensuring numerical ranges and categorical choices strictly comply with valid domains.
Figure 2: Overall framework of SciDC. General LLM transforms knowledge documents into standardized rules, which are divided into 3 layers constraining the reliable generation of domain LLM.

Datasets

The framework was evaluated across three distinct scientific domains and one legal benchmark:

  • Industrial Formulation Design: 458 formulation samples paired with a 1.7k-token empirical guideline document for optimizing chemical component ratios.
  • Clinical Tumor Diagnosis: 200 virtual medical records verified by professionals, evaluated against the 8th edition of the American Joint Committee on Cancer (AJCC) TNM staging guidelines.
  • Chemical Retrosynthesis Planning: 201 reactions randomly selected from the USPTO-full dataset, paired with 25,214 official reaction templates from AiZynthFinder.
  • LegalBench: The "hearsay" evidence task, used to test the framework's generalizability to non-scientific, rule-bound domains.

Key Insights and Ideas

  • Privacy-Preserving Collaboration: By using a cloud-based GLLM as a one-time compiler to generate the rule code, organizations can use smaller, locally hosted domain models (DLLMs) for actual inference. This keeps sensitive patient or proprietary industrial data entirely private.
  • Fine-Tuning Alone is Insufficient: The experiments showed that even domain-specific models (like ChemDFM) frequently violate fundamental rules of their own subject matter when left unconstrained. Hard decoding constraints act as a necessary safety net.
  • The Power of Local Backtracking: Instead of discarding an entire generation when an error occurs (which is computationally expensive), SciDC's middle layer identifies the exact semantic unit that caused the logical failure and regenerates only that segment.

Key Results

SciDC consistently outperformed vanilla generation methods across all backbones (Qwen3-4B, Qwen3-14B, and ChemDFM-8B), yielding an average absolute accuracy improvement of 12%.

Table 2: Main results for SciDC framework on 3 distinct domain. We report average scores for 3 random seeds. Overall shows the average accuracy of the three tasks. ∆stands for delta values after applying our framework.
  • Formulation Design: For Qwen3-14B, SciDC boosted the validity of generated formulations from 50.9% to 75.5% and the success rate from 50.4% to 68.3%.
  • Tumor Diagnosis: Exact match accuracy for Qwen3-14B rose from 72.0% to 79.5%, achieving 100% clinical validity in its structured assessments.
  • Cross-Domain Generalization: When tested on LegalBench's hearsay task, a SciDC-equipped Qwen3-14B achieved an accuracy of 86.46%, outperforming both GPT-4 (85.11%) and Claude 3.5 Sonnet (86.17%).

Limitations and Future Work

Despite its success, SciDC has two primary limitations:

  • Inference Latency: Enforcing middle-layer checks and local backtracking requires multiple separate calls to the inference engine. In practice, this overhead made SciDC roughly 3x slower than vanilla generation. Optimizing this at the decoder architecture level (e.g., tighter integration with engines like vLLM) remains future work.
  • The Challenge of Tacit Knowledge: The framework can only enforce rules that are explicitly codified. In one failure case, the model adjusted a chemical ratio to satisfy a specific rule but failed to scale down other components, resulting in a total mass fraction exceeding 100%. Explicitly codifying fundamental physical laws (like mass conservation) is required to prevent these edge cases.

Summary updated

Abstract

Large language models (LLMs) have shown strong knowledge reserves and task-solving capabilities, but still face the challenge of severe hallucination, hindering their practical application. Though scientific theories and rules can efficiently direct the behaviors of human manipulators, LLMs still do not utilize these highly-condensed knowledge sufficiently through training or prompting. To address this issue, we propose \textbf{SciDC}, an LLM generation method that integrate subject-specific knowledge with strong constraints. By adopting strong LLMs to automatically convert flexible knowledge into multi-layered, standardized rules, we build an extensible framework to effectively constrain the model generation on domain tasks. Experiments on scientific tasks including industrial formulation design, clinical tumor diagnosis and retrosynthesis planning, consistently demonstrate the effectiveness of our method, achieving a 12\% accuracy improvement on average compared with vanilla generation. We further discuss the potential of LLMs in automatically inductively summarizing highly-condensed knowledge, looking ahead to practical solutions for accelerating the overall scientific research process. All the code of this paper can be obtained (https://github.com/Maotian-Ma/SciDC).
BibTeX
@misc{ma2026scientific,
  author = {Maotian Ma and Zheni Zeng and Zhenghao Liu and Yukun Yan},
  title = {{Scientific Knowledge-driven Decoding Constraints Improving the Reliability of LLMs}},
  year = {2026},
  eprint = {2604.06603},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2604.06603},
}
Figure