Grammar-constrained decoding and domain validation 00:00:01 A legal word on the wrong receipt A brass typewheel can print only the permitted payment statuses. It clicks cleanly into “paid.” Ravi checks the original ledger entry: void. The wheel produced perfect syntax while the application was one step away from storing a false claim. A parser can restrict the next tokens to those that keep a partial output compatible with a grammar. At each generation step the engine masks ineligible vocabulary entries and samples among what remains. Token boundaries do not always match Jay son characters, so a correct implementation tracks possible continuations at the tokenizer boundary. Supported schema features depend on the engine. At each position, mark which next tokens still allow a complete valid value. An illegal prefix disappears immediately. A legal prefix can still lead to more than one meaning for the business. 00:00:53 Watch the allowed characters The output has reached the enum field. The engine knows which continuations the supported grammar accepts. Exclude tokens that cannot lead to paid or void. Continue until the full object parses. Syntax succeeds but the business invariant fails. Store the discrepancy for review. 00:01:13 Follow grammar into evidence A partial prefix remains admissible when at least one completion can satisfy the supported grammar. It can be valid to continue generating without being valid to accept the prefix as a complete object. After an opening quote, a string prefix may still complete to paid. It cannot yet be accepted as the final status. Map a grammar state to eligible tokens and mask others before normalization. Constrained decoding can change the relative probabilities of the remaining options and incur runtime overhead for complex grammars. For an enum containing paid and void, the mask rules out a third label but cannot determine which of the two matches the invoice. Check completed output against source evidence and business constraints before acting. Use bounded recovery on malformed or incomplete results and preserve an explicit uncertain state when neither enum value is supported. The receipt is void while the model emits valid Jay son with status paid. A source or ledger comparison must reject the proposed update. Constraints can eliminate malformed syntax without establishing that an amount came from a receipt or that an action is authorized. Use grammar constraints for shape, parse the completed output, then validate domain rules and evidence. An incomplete stream must not be committed merely because its prefix remains valid. Compare throughput and retry costs with post-generation parsing. 00:02:39 Can the ledger change? A schema-constrained generator produces a parseable status. What still determines whether it can update a payment record? A grammar controls possible representations, not the truth of a business assertion. Use the grammar to control the shape, then test the proposal against the authorized ledger. The safe outcome here is a visible discrepancy for review.