BriConstrain: Geometrically Constrained Decoding for Autoregressive Brick Assembly Generation

Nadav Magar, Amir Hertz, Ariel Shamir, Or PatashnikarXiv 2026

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.

Unconstrained LLMs generate interpenetrating LEGO parts (marked in red), whereas BriConstrain enforces geometric validity to produce clean, collision-free assemblies.

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.

Figure 2. Constrained decoding of one part. Top: how one part is written in BrickNet’s format and in ICLF; colors mark which fields the model chooses freely and which our method constrains. (a) Given the caption and the parts built so far, the model selects the next part type and its parent; parents without any valid attachment are vetoed (olive box; the vetoed parent is shown in red, Sec. 4.2). (b) The geometric oracle lists the ways the part can attach to its parent (Sec. 4.1); each candidate is placed in the build so far, S, and checked for collisions. (c) The candidates, written as tokens, form a tree; tokens that lead only to colliding candidates are penalized by −β before sampling, and removed in the hard-mask case β →∞(Sec. 4.2). In the tree, . . . stands for the continuations the oracle does not offer. The dashed box zooms in on the last decoded token: its original next-token probabilities and the constrained ones, in which the colliding 270 and the continuations the oracle does not offer are lowered by β. The decoded part joins the build and the loop repeats.

Here is how a single brick gets placed:

  1. 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.
  2. 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).
  3. 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.
  4. 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.
Figure 3. Qualitative comparison on BrickNet validation captions. Each row shows BrickNet-14B (left group) and our ICLF model (right group). The quoted excerpts are the literal model inputs. Columns: freeform decoding (B0/I0), rejection sampling with N=8 tries per part, the placement filter alone (B3/I2), and our full method with the parent veto (B4/I3). Colliding parts are tinted red and counted in the pills.

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

Abstract

Language models can generate LEGO$^\circledR$ assemblies from text, but their builds often contain parts that collide or attach to nothing. The usual approach of rejecting and resampling invalid placements discards decoded tokens without guaranteeing a valid build. We present BriConstrain, a constrained decoding method that restricts a pretrained language model's next-token probabilities before sampling, steering it towards valid placements. Because the validity of a brick placement depends on the non-predetermined build state, it cannot be compiled into a fixed grammar and must be checked dynamically. However, checking the validity of a brick before sampling is challenging as the space of valid placements is combinatorially large and cannot be enumerated exhaustively. Our key idea is to narrow the search space by constraining how parts attach rather than which parts attach to each other. Concretely, given the model's predictions of the currently placed part, and the previously placed parent it wants to connect to, we constrain the model's choice of how they attach. This allows us to span the space of part attachments, using a precomputed geometric oracle, and to effectively filter out colliding options. With valid attachment candidates in hand, we bias the model's next-token distribution towards the remaining valid candidates. We evaluate our method on two LEGO$^\circledR$ formats and models: BrickNet, which annotates connectivity explicitly, and our proposed Implicit Connectivity LDraw Format (ICLF), which uses numeric values for placements and leaves connectivity implicit. Our method raises collision-free builds from 31% to 91% on BrickNet and from 15% to 65% on ICLF, and outperforms rejection sampling on both formats at about 60% of its decoding cost.
BibTeX
@misc{magar2026briconstrain,
  author = {Nadav Magar and Amir Hertz and Ariel Shamir and Or Patashnik},
  title = {{BriConstrain: Geometrically Constrained Decoding for Autoregressive Brick Assembly Generation}},
  year = {2026},
  eprint = {2611.33135},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2611.33135},
}
Figure