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.
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):
- 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.
- Multi-Layered Decoding Constraints: This executable code enforces constraints on the DLLM at three distinct granularities during generation:
- 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).
- 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.
- 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.
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%.
- 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