Language models can generate LEGO® 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® 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.
Figures & tables
Figure 1: We constrain the output of large language models for LEGO ® generation to enforce geometric validity. Each scene shows a build decoded freely (left) and with our method (right) for the same caption, by BrickNet-14B or, bottom left, by our ICLF model. Red marks interpenetrating parts; each inset zooms in on a colliding pair (bricks in blue and orange, the volume both occupy in red).
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.
BrickNet checker (%)
ColSAT (%)
Visual proxies
Arm
Parts
CF ↑
Part inv. ↓
Build inv. ↓
CF ↑
Part inv. ↓
Build inv. ↓
SigLIP ↑
DINO ↑
VQA ↑
BrickNet-14B, BN-val-512 (2048 attempts per arm)
B0 Freeform
30.7
30.9
23.7
16.5
25.7
23.6
18.1
0.152
0.630
0.264
B1 + grammar & catalog
30.6
29.1
24.8
17.7
24.7
24.2
18.9
0.151
0.632
0.257
B2 + collision-aware mates
33.3
32.7
19.8
14.2
27.6
20.2
16.3
0.151
0.630
0.255
B3 + collision-aware placements
36.1
47.4
7.4
6.0
39.1
9.8
9.5
0.150
0.626
0.261
Table 1: Constraint ablation. Each row adds one constraint to the row above (Sec. 4.2 ); the last row of each block is rejection sampling, which re-draws each colliding part up to N=8 times (Sec. 6.1 ). Top: BrickNet-14B on BN-val-512; bottom: our ICLF model on 427 BN-val captions; four samples per caption. Parts: mean number of parts per parsable build; the other metrics are defined in Sec. 5.2 . Colors mark the three best values in each column, per block.
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.
Figure 4: Validity against cost. Share of valid parts against wall time per output token (total decoding time, including rejected attempts, per token kept in the final build) relative to freeform decoding. We compare rejection sampling with N tries (circles and squares) with our method (stars) on both BrickNet and ICLF (names match Table 1 ). Our method produces more valid parts than any rejection budget, at a lower cost.
Figure 5: Hard versus soft constraints on BrickNet-14B (left) and ICLF (right). Each curve sweeps the placement penalty from freeform decoding (square) through β=0,1,2,4,8 (circles) to the hard mask (diamond).
Figure 6: Limitations. When the base model cannot build the captioned object (left), our method makes the build collision-free (right) but no more recognizable than unconstrained decoding (middle): we constrain how parts attach, not which parts the model chooses, nor by the appearance of a placement
Appendix figures & tables10 assets
Supplementary material from the paper’s appendix.
Appendix
Figure S1 : One build in three forms: the BrickNet connector program, the ICLF records of the compiled LDraw file, and the LDraw file itself. BrickNet writes two lines per part (the part, then its attachment edge), ICLF and LDraw write one line per part. Parts appear in the same order in all three forms.
BrickNet
ICLF
Candidates per pair, median
175
175
Tokens per attachment, mean
9.6
12.7
Tree depth, median
10
14
Tree nodes, median
753
947
Mean branching, two widest levels
15.8, 4.7
5.7, 2.0
Mean branching, other levels
< 3
≤ 1.8
Appendix
Table S1: Shape of the candidate prefix tree before collision filtering, over 200 occurrence-weighted part-type pairs from BrickNet’s validation builds. Both columns hold the same placements (strings that describe one physical placement merged), written in each format and tokenized with that model’s tokenizer. Branching: the mean number of children of a node at one tree level, averaged over pairs; BrickNet’s two widest levels are the parent-connector and child-connector tokens, ICLF’s are its first two tokens.
Family
Edges
Empirical
Enumerated
Union
Stud
29,455
78.16
97.68
97.98
Axle
1,641
63.74
15.30
67.58
Hinge
544
90.99
43.20
92.46
Ball
60
78.33
73.33
85.00
Fixed
548
95.99
100.00
100.00
All edges
32,248
77.94
92.56
96.35
Appendix
Table S2: Oracle coverage (%) of BrickNet validation builds. The last row averages within-pair coverage across 5,524 pairs.
Arm
Parse
CF
Time/tok
(%) ↑
(%) ↑
( × freeform) ↓
BrickNet-14B, BN-val-512
B0 freeform
94.2
30.9
1.00
B1 + grammar & catalog
99.5
29.1
–
B4 + parent veto
99.4
90.8
1.26
Rejection, N=2
100.0
49.6
1.65
Appendix
Table S3 : Parse yield and decoding cost of the final mesh-checker decoders on both models. Parse: % of the attempts (2048 for BrickNet-14B, 1708 for ICLF) that are parsable; CF: collision-free attempts under the BrickNet checker (Table 1 in the main paper). Time/tok: wall time per token kept in the final build (rejection counts its discarded tries), relative to freeform decoding on one B200 GPU (96 builds per configuration).
CF
Part inv. (%) ↓
Time/tok
Arm
(%) ↑
BN
ColSAT
( × freeform) ↓
BrickNet-14B, BN-val-512
Freeform (B0)
30.9
23.7
23.6
1.00
Rejection, N=2
49.6
10.5
13.5
1.65
Rejection, N=4
64.3
5.3
9.1
2.01
Rejection, N=8
74.3
2.7
6.9
2.14
Appendix
Table S4: Constrained decoding against per-part rejection sampling at every budget: the data of Fig. 4 in the main paper, four samples per caption. CF: collision-free builds (BrickNet checker); Part inv.: % of parts that are the later-placed part of a colliding pair. Rejection re-draws a part while the collision checker flags it or it does not parse, up to N tries. Time/tok: wall time per token kept in the final build (rejection counts its discarded tries), relative to freeform decoding on one B200 GPU (96 builds per configuration).
Overrides
Invalid
In oracle
Invalid (%)
Prob. outside
β
(% att.)
(%)
(%)
in oracle
off oracle
Ai (median)
1
18.1
69.8
73.2
93.1
6.5
0.993
2
16.4
71.0
71.4
94.7
11.9
0.998
4
11.2
72.0
72.1
95.1
12.3
1.000
8
4.7
70.4
65.3
94.1
25.7
1.000
Appendix
Table S5 : Overrides of the soft penalty, BrickNet-14B, 256 replayed builds per β . Overrides: share of all attachments at which a sampled token left a non-empty Ai (attachments with an empty Ai , 7–10%, are not counted). Invalid: the committed part collides with an earlier part under BrickNet’s mesh checker (Sec. B.1 ). In oracle: overrides whose committed placement is an oracle placement rejected by the collision test. Prob. outside Ai : the model’s probability mass outside Ai at the token where it left, before the penalty.
Figure S2 : Qualitative examples (1/2): BrickNet-14B on BN-val-512 captions. Columns follow Table 1 in the main paper without B1. “Colliding” counts the parts in a collision under the BrickNet mesh checker.
Figure S3 : Qualitative examples (2/2): BrickNet-14B on BN-val-512 captions. Columns follow Table 1 in the main paper without B1. “Colliding” counts the parts in a collision under the BrickNet mesh checker.
Figure S4 : Qualitative examples (1/2): our ICLF model. Columns follow Table 1 in the main paper. “Colliding” counts the parts in a collision under the BrickNet mesh checker.
Figure S5 : Qualitative examples (2/2): our ICLF model. Columns follow Table 1 in the main paper. “Colliding” counts the parts in a collision under the BrickNet mesh checker.
Constrained decoding steers language model outputs to satisfy formal or task-specific rules while balancing validity, quality, and faithful probabilities.