When a large language model generates a typo in a sentence—such as writing "the cat sate on the mat"—human readers can easily infer the intended meaning. The underlying grammar of natural language is flexible and highly forgiving.
Chemistry is entirely different. If a generative model makes a single character error while outputting a molecular string, or slightly misplaces a coordinate in a 3D molecular graph, the result is not just a "typo." It frequently violates fundamental physical laws, such as giving a carbon atom five bonds or creating a physically impossible, distorted ring. In the literature, these invalid outputs are known as structural or chemical hallucinations. Because deep learning models naturally operate on continuous probabilities or unconstrained token sequences, forcing them to respect the rigid, discrete laws of chemical valency is one of the most significant hurdles in AI-driven drug and materials discovery.
To solve this, a major research direction has emerged focused on embedding structural validity constraints directly into the generative process. Rather than relying on models to blindly memorize chemistry from data, researchers are redesigning representations, architectures, and optimization loops to ensure that generated molecules are physically plausible and synthesizable.
The Fragility of Chemical Strings and Graphs
To understand why standard generative models fail, we must look at how they represent molecules. The most common representation is SMILES (Simplified Molecular Input Line Entry System), which flattens a 2D molecular graph into a text string.
As Fang et al. explain, SMILES strings are syntactically brittle. A single misplaced parenthesis or character completely alters or destroys the structural meaning, forcing models to waste immense computational resources generating invalid strings. When large language models are applied to chemistry without modification, Wang et al. observe that they consistently produce non-synthesizable or physically impossible structures because they lack an inherent mechanism to obey chemical constraints.
The issue is not unique to text. When models generate 3D molecules atom-by-atom, they face similar geometric failures. As Jin et al. point out, small errors in predicting individual atoms or bond orders accumulate rapidly, leading to catastrophic violations of valency rules.
Atom-by-Atom Generation (Error Accumulation):
[C] ---> [C=C] ---> [C=C-C] ---> [Invalid Pentavalent Carbon] ❌
Fragment-Based Generation (Inherent Validity):
[Benzene Ring] + [Hydroxyl Group] ---> [Phenol] Valid
Building a molecule atom-by-atom requires the model to maintain a flawless global understanding of chemistry while making micro-level decisions. Without structural priors, an autoregressive model might place several atoms in a row, only to realize too late that it cannot close a chemical ring without violating realistic bond lengths or angles, a limitation highlighted by Zhang et al..
Shifting the Vocabulary to Fragments and Motifs
The most intuitive solution to this problem is to change the model's "vocabulary." If generating individual characters or atoms is too risky, why not generate molecules using pre-validated chemical building blocks?
This approach, known as fragment- or motif-based generation, shifts the model's operational level from individual atoms to larger functional groups (like benzene rings, methyl groups, or complex scaffolds). Podda et al. demonstrate that treating these molecular substructures as "words" in a language model allows the system to inherently respect chemical constraints during generation, drastically boosting the validity rate of the output.
By assembling pre-constructed motifs, the model completely bypasses the risk of creating distorted local geometries or impossible valencies. As Ochoa et al. note, fragment-based assembly naturally captures the inherent stability and physical rules of larger structures. However, assembling fragments introduces its own challenge: ensuring that the connections between fragments remain valid. To address this, Geng et al. developed connection-aware motif mining, which extracts not just the fragments themselves from chemical libraries, but also the precise grammatical rules governing how they are allowed to link together, preserving critical properties like aromaticity without relying on heavy post-processing filters.
Injecting Chemical Common Sense and Feedback Loops
When changing the underlying representation is not an option—such as when using large multimodal models or continuous diffusion frameworks—researchers inject structural constraints through explicit guidance, specialized pre-training, or domain feedback.
1. Mathematical Projections in Diffusion
In continuous generative frameworks like diffusion models, the model gradually denoises a random distribution into a molecular graph. Left unconstrained, the model often drifts into invalid regions of chemical space. To counteract this, Sharma et al. introduced a "plug-and-play" framework called PRODIGY. It inserts a non-differentiable projection step directly into the denoising loop, mathematically forcing the intermediate states to satisfy strict structural rules without requiring the underlying model to be retrained.
2. Rule-Based Pre-Training
Another strategy is to teach the model the "grammar" of chemistry before it ever attempts to design a new molecule. Wei et al. designed a pre-training framework (PMSR) that forces models to recover masked molecular fragments while adhering to strict structural constraints. This explicitly teaches the network valence rules and atom conservation laws. Similarly, Wu et al. show that pre-training chemical language models on massive datasets of known, stable compounds imparts an implicit "structural common sense," preventing the generation of physically impossible geometries later on.
3. Domain Feedback and Retrieval
For conversational models and LLMs, researchers ground the generation process by wrapping the model in an environment that provides real-time chemical feedback. Wang et al. demonstrate that combining in-context learning with verified chemical examples and iterative domain feedback effectively constrains the model's search space, preventing structural hallucinations by forcing the model to cross-reference its outputs with real-world chemical properties.
The Imperative for Accurate Evaluation
As generative models become more sophisticated at navigating structural constraints, the benchmarks used to evaluate them must keep pace. A sobering finding by Nikitin et al. revealed that standard benchmarks for 3D molecular generation frequently suffer from chemically inaccurate valency definitions and flawed bond-order calculations.
Because of these flaws, evaluation toolkits have routinely classified chemically impossible structures as "valid," artificially inflating the performance metrics of weaker models. This underscores a vital truth in the field: achieving true chemical validity requires absolute precision not just in how models generate molecules, but in how we mathematically define and verify the laws of chemistry within our evaluation pipelines.