MIT Researchers Create HardFlow Algorithm to Make AI Systems Safer in High-Stakes Environments
In a crowded factory, a robot needs to move from one station to another without colliding with human workers. "Pretty close" is not an option. Now, MIT researchers have developed…

In a crowded factory, a robot needs to move from one station to another without colliding with human workers. “Pretty close” is not an option. Now, MIT researchers have developed a technique that helps generative AI systems produce outputs that satisfy these kinds of nonnegotiable safety requirements without sacrificing quality.
The method, called HardFlow, enables pretrained generative AI models to meet strict constraints at the final output stage rather than forcing every intermediate step to satisfy those requirements. This gives the model more freedom to find high-quality solutions that are still feasible when the generation process completes.
“The promise of generative AI is its ability to explore a rich space of possibilities, but the real world places boundaries on which possibilities are acceptable,” said Navid Azizan, the Alfred H. and Jean M. Hayes Career Development Associate Professor in MIT‘s Department of Mechanical Engineering and Institute for Data, Systems, and Society. “Our approach lets us preserve that generative power while enforcing the nonnegotiable requirements of high-stakes or safety-critical applications.”
Azizan led the research team, which included graduate students Zeyang Li and Kaveh Alim. Their paper appears in IEEE Transactions on Pattern Analysis and Machine Intelligence.
Limitations of Current Methods
The problem with existing approaches is that they often restrict the entire generation process to satisfy hard constraints at every step. While this ensures compliance, it can prevent the model from reaching a better final solution. A robot path planner using these methods might find a collision-free route, but not necessarily the shortest one.
“For constraint satisfaction, what ultimately matters is the model’s final output, since the internal process is discarded,” Li said. “By not requiring every intermediate step to satisfy the constraints, we give the model more freedom to find high-quality solutions that are still feasible in the end.”
Technical Implementation
HardFlow reformulates hard-constrained sampling as a trajectory-optimization problem, borrowing tools from control theory. This allows the system to make subtle corrections throughout the generation process while enforcing hard constraints only on the final result. Solving this optimization problem around a neural network with hundreds of interconnected layers required the researchers to leverage the structure of flow-matching models, decomposing the problem into smaller, manageable steps.
“Essentially, we transformed the trajectory-optimization problem into something that preserves the key properties of the original problem, but can be solved very efficiently at deployment time,” Azizan said.
Enhanced Capabilities and Results
This reformulation also enables HardFlow to incorporate additional goals beyond constraint satisfaction. The algorithm could find a collision-free robot path that is simultaneously the shortest distance to the target, something existing methods typically cannot achieve.
In tests across robotic manipulation, maze navigation, and text-guided image editing, HardFlow achieved perfect constraint satisfaction while outperforming baseline methods on solution quality measures. When tested with a robotic manipulator, the system avoided collisions with obstacles while identifying the quickest path to the target object. Competing methods either resulted in collisions or found significantly slower routes.
The technique works with pretrained diffusion and flow-matching models without requiring any retraining, making it immediately applicable to existing systems. The researchers plan to extend the framework to settings where the AI model itself can be updated, allowing constraint satisfaction and sample quality to improve in a more adaptive manner over time.


