Generative artificial intelligence has become remarkably good at producing answers that are almost right. Diffusion models paint images that closely match a text prompt, and flow-matching models generate trajectories, designs, and signals that land near what a user asked for. But in the settings where AI could matter most — a robot navigating a crowded factory floor, a controller managing a physical process, a vision system guiding machinery — almost right can be dangerously wrong. A path that is nearly collision-free is still a collision. A control input that approximately respects a physical limit can still break the machine. A new algorithm developed at the Massachusetts Institute of Technology, called HardFlow, tackles precisely this gap, and it does so without requiring the underlying generative model to be retrained at all.
The research, led by senior author Navid Azizan, the Alfred H. and Jean M. Hayes Career Development Associate Professor in MIT’s Department of Mechanical Engineering and the Institute for Data, Systems, and Society, appears in the journal IEEE Transactions on Pattern Analysis and Machine Intelligence. Azizan, who is also a principal investigator in the Laboratory for Information and Decision Systems, worked with lead author Zeyang Li, a graduate student in mechanical engineering and LIDS, and Kaveh Alim, a graduate student in IDSS and LIDS. Their central insight is deceptively simple: when it comes to satisfying hard constraints, what matters is the model’s final output, not the intermediate steps along the way. Yet most existing methods do exactly the opposite, clamping the model at every step of generation and, in doing so, strangling its ability to find good solutions.
To understand why this matters, it helps to look at how pretrained generative models actually work. Models such as Stable Diffusion and FLUX learn to create new data by transforming random noise into structured output through a sequence of denoising steps. This iterative process is what gives them their creative power: they explore a rich space of possibilities before settling on an answer. When users need those answers to obey strict requirements — safety rules, physical laws, task-specific limits known as hard constraints — the standard approach is a technique called projection-based sampling. At each intermediate step, the partial solution is forcibly projected onto the set of constraint-satisfying values, dragging the sample back into the feasible region over and over again.
The problem, as the MIT team recognized, is that constraining the entire generation process is both wasteful and counterproductive. The internal trajectory of a generative model is discarded once the final output is produced, so there is no reason every intermediate sample must be feasible. Forcing feasibility at every step removes degrees of freedom the model could otherwise use to explore, and it can prevent the sampler from ever reaching a better final solution. Worse, projection-based methods typically focus solely on constraint satisfaction, ignoring the opportunity to improve other qualities of the answer — for instance, shortening a robot’s trajectory while keeping it collision-free. An answer that merely avoids crashing is not the same as a good answer.
HardFlow flips the logic. Instead of enforcing constraints at every intermediate step, the algorithm gives the model freedom to roam during generation and enforces the hard constraints only on the final output. The trick is in how it steers the process. The researchers reformulated hard-constrained sampling as a trajectory-optimization problem, borrowing tools from optimal control theory. This framing treats the sequence of denoising steps as a controlled trajectory that can be nudged toward a goal, with subtle corrections applied along the way and the constraints imposed at the destination. Control theory, Azizan notes, provides a powerful framework for formalizing the optimal way to make those corrections — turning what might otherwise be ad hoc clamping into a principled steering problem.
Of course, formulating the problem is easier than solving it. The trajectory-optimization problem wraps around an enormous neural network, potentially hundreds of interconnected layers deep, and optimizing over such a structure directly would be computationally intractable at deployment time. The MIT team’s solution was to exploit the mathematical structure of flow-matching models, which allowed them to decompose the global trajectory problem into a sequence of smaller, single-step subproblems. Through systematic transformations and carefully chosen approximations, they derived an efficient, scalable algorithm that preserves the key properties of the original optimization problem while remaining fast enough to run when the model is actually being used. Essentially, as Azizan describes it, the team transformed the trajectory-optimization problem into something that can be solved very efficiently at deployment time.
This deployment-time operation is one of HardFlow’s most practical advantages. The technique is plug-and-play: it can be applied to any pretrained generative model without retraining, fine-tuning, or modifying the network’s weights. In an era when powerful foundation models are widely available and constantly being updated, a method that layers constraint satisfaction on top of existing models — rather than baking it in through expensive retraining — dramatically lowers the barrier to deploying generative AI in safety-critical contexts. Hospitals, factories, and autonomous systems do not need to rebuild their models; they simply need a smarter sampler.
The reformulation as an optimization problem also buys something projection methods cannot offer: the ability to jointly optimize for quality. Because HardFlow treats constrained generation as an optimization, additional objectives can be folded directly into the framework. A robotic path planner using HardFlow, for example, does not merely find any collision-free route from one machine to another — it can find the shortest or quickest collision-free route. Li emphasizes that this joint handling of feasibility and quality is what allows the framework to perform substantially better than existing methods, which typically treat constraint satisfaction as the sole goal and leave solution quality to chance.
The experimental evidence spans three domains: robotic manipulation, maze navigation, and text-guided image editing. Across all of them, HardFlow achieved perfect constraint satisfaction — every single output met the required constraints — while consistently outperforming baseline methods on measures of solution quality. In the robotics experiments, the algorithm enabled a robotic manipulator to avoid collisions with obstacles while simultaneously finding the quickest path to a target object. Most competing methods, by contrast, either produced collisions outright or found paths that took significantly more time to execute. Notably, HardFlow’s computational cost was comparable to or lower than that of most rival techniques, meaning the gains in quality and safety did not come at the price of impractical runtimes.
The implications reach well beyond the lab. Generative models are increasingly being proposed for roles in which their outputs must obey nonnegotiable rules: robots sharing space with human co-workers, controllers governing physical infrastructure, and vision systems whose errors carry real consequences. HardFlow offers a way to preserve the exploratory power that makes generative AI valuable while guaranteeing that the final answers respect the boundaries the real world imposes. As Azizan puts it, the promise of generative AI lies in its ability to explore a rich space of possibilities, but the real world places limits on which possibilities are acceptable — and his team’s approach is designed to preserve that generative power while enforcing the nonnegotiable requirements of high-stakes applications. The researchers note that future work could extend the framework to settings where the AI model itself is also updated during use, allowing constraint satisfaction and sample quality to improve in a more adaptive, closed-loop manner. For now, HardFlow stands as a demonstration that the path to trustworthy generative AI may not run through bigger models or more training data, but through smarter control of the generation process itself.
Subject of Research: Hard-constrained sampling for pretrained generative AI models via trajectory optimization
Article Title: New method enables AI for safety-critical situations
Article References: New method enables AI for safety-critical situations. (n.d.). Original publication
Image Credits: AI Generated
DOI: Not provided
Keywords: HardFlow, generative AI, diffusion models, flow-matching models, hard constraints, trajectory optimization, optimal control, robotics, constraint satisfaction, MIT, safety-critical AI, sampling algorithms
Cite Scienmag News
Reid Dalton. (October 4, 2026). MIT’s HardFlow algorithm steers generative AI around hard constraints without retraining. Scienmag. https://scienmag.com/mits-hardflow-algorithm-steers-generative-ai-around-hard-constraints-without-retraining/
Reid Dalton. "MIT’s HardFlow algorithm steers generative AI around hard constraints without retraining." Scienmag, 4 October 2026, https://scienmag.com/mits-hardflow-algorithm-steers-generative-ai-around-hard-constraints-without-retraining/. Accessed 4 October 2026.
Reid Dalton. "MIT’s HardFlow algorithm steers generative AI around hard constraints without retraining." Scienmag. October 4, 2026. https://scienmag.com/mits-hardflow-algorithm-steers-generative-ai-around-hard-constraints-without-retraining/

