TL;DR
Large language models can generate LEGO® designs from text prompts, but left to their own devices, they frequently violate physics—shoving bricks right through one another or floating them in midair. Instead of generating bad placements and throwing them away, BriConstrain looks ahead during inference and dynamically masks out physically impossible next-tokens before the model even samples them. The result? Up to a 3x jump in completely collision-free builds at a fraction of the computational cost of standard trial-and-error methods.
What Problem Does This Paper Address?
Generating a 3D LEGO® assembly autoregressively—brick by brick, token by token—requires strict spatial discipline. Every newly added piece must attach via compatible connectors and avoid colliding with every single piece placed before it.
Current LLM-based generators try to solve this in two ways: either hoping the model learns 3D physics implicitly during training (which still leaves plenty of intersecting plastic), or using rejection sampling—generating a brick's coordinates, running a collision check, and rolling back to try again if it fails. Rejection sampling wastes massive amounts of compute discarding bad tokens and still fails if the model backs itself into a geometric corner.
What we really want is constrained decoding, where invalid tokens are masked out before sampling. Standard constrained decoding works great for static rules (like forcing an LLM to output valid JSON). Here, however, the rules are dynamic (validity changes with every brick added) and combinatorially vast (a brick placement spans multiple tokens across thousands of part types and continuous angles, making it impossible to exhaustively check every option ahead of time).
Methods
BriConstrain makes lookahead geometric checking tractable without retraining the underlying LLM. The secret is dividing the labor: let the LLM decide what to connect, and only constrain how they connect.
Here is how a single brick gets placed:
- Part & Parent Selection: Given the text prompt and current build, the LLM freely chooses the next brick type and which existing "parent" brick it attaches to.
- The Geometric Oracle: Because relative attachments only depend on the two part types (and not the rest of the build), the authors precompute a massive lookup table called the geometric oracle. It combines grid-sampled connector pairs with empirical, off-grid attachments mined from human builds (covering 96% of validation attachments).
- Dynamic GPU Filtering & Prefix Trees: The oracle hands over a finite list of candidate poses for the chosen brick pair. A fast, batched GPU collision checker tests all candidates against the current 3D assembly simultaneously. Surviving valid placements are tokenized into a prefix tree, which masks (or penalizes by a hyperparameter $\beta$) any next-token logits that would lead to a collision.
- Parent Veto: What if the LLM chooses a parent brick that is completely boxed in, leaving zero valid attachments? Without intervention, the decoder would have to fall back to unconstrained guessing. The parent veto looks ahead one step earlier, forbidding the LLM from selecting any parent that yields an empty candidate set.
The authors test this across two representations: BrickNet (which explicitly names connectors like studs and holes) and their newly proposed Implicit Connectivity LDraw Format (ICLF), where the LLM outputs raw relative $(x,y,z)$ offsets and rotations without explicit connector hints.
Datasets
- BrickNet Dataset: Curated human-designed digital LEGO® assemblies (built on the community LDraw standard of 24,000+ parts) paired with text captions. Used directly to evaluate the pretrained BrickNet-14B model, and converted to ICLF (with decorative minifigures removed) to LoRA fine-tune a Qwen3.6-27B model.
- BN-val-512: A held-out validation set of 512 captions (427 non-minifigure captions for ICLF) used for all evaluations.
Key Insights and Ideas
- Don't trust an LLM's spatial confidence: The authors tested "soft" constraints (penalizing invalid tokens by $\beta$ rather than hard-masking them) to see if a confident LLM could smartly override the incomplete oracle. It flopped. Even when overriding a strong penalty, ~70% of the LLM's confident overrides were straight-up collisions. Hard masking ($\beta \to \infty$) wins decisively.
- The Parent Veto is the real MVP: Filtering placements after a parent is chosen cuts BrickNet's invalid parts from 23.7% down to 7.4%. Nearly all (99.9%) of those remaining errors happened because the chosen parent had zero valid space left. Adding the parent veto crushed the invalid part rate down to 0.5%.
- Format changes tree geometry, not efficacy: Explicit connectors (BrickNet) create wide, shallow token trees (big decisions on 1–2 tokens), while numeric coordinates (ICLF) create deep, narrow trees (decisions spread across digits). BriConstrain slashes collisions in both.
Key Results
BriConstrain outperforms rejection sampling (up to $N=8$ retries per part) in both structural validity and speed:
- BrickNet-14B: Collision-free builds jump from 30.9% (freeform) and 74.3% (rejection sampling) to 90.8% with BriConstrain, while preserving visual similarity (DINOv2 and VQA scores remain virtually unchanged).
- ICLF (Qwen3.6-27B): Collision-free builds leap from 14.6% (freeform) and 32.8% (rejection sampling) to 65.2%—though VQA prompt-adherence dips slightly (0.296 to 0.262).
- ** Speed & Cost: Because BriConstrain never rolls back or re-runs the LLM, it requires only 1.26x (BrickNet) and 1.56x (ICLF) the wall-time per token of unconstrained decoding—roughly 60% of the decoding cost** of 8-try rejection sampling (2.14x and 2.47x).
- Independent Verification: Evaluated on ColSAT—an independent collision checker from BrickLink Studio that the decoder never sees—collision-free builds still jump from 25.7% to 64.1% (BrickNet) and 16.7% to 58.7% (ICLF), proving the decoder isn't just exploiting mesh quirks.
Limitations and Future Work
- Geometry $\neq$ Physics: BriConstrain checks for overlapping volumes and valid connections, not gravity or structural stability. A generated build won't intersect itself, edit-free, though it might still tip over on a real desk.
- Format & Base Model Dependencies: The method requires formats where parts explicitly declare a parent, and it leaves part type unconstrained (meaning an LLM could pick a massive brick that simply fits nowhere). Furthermore, it only fixes how bricks attach, not creative aesthetics—if the base LLM doesn't know what a Batmobile looks like, BriConstrain will just help it build a collision-free blob.
- Future Work: Extending this "closed-form oracle + dynamic token masking" recipe to other domains where LLMs struggle with hard physical rules, such as robot action planning and physical simulation.
Summary updated