Transformers.js v4.3: Structured Output in the browser
Transformers.js v4.3 is out, and the big one is structured output. With the new @huggingface/transformers-structured-output package you can force a model to follow an exact JSON Schema or regex, directly in the browser. No more parsing markdown fences and hoping the model picked the right property names. In this video I walk through how constrained decoding works, how the new package hooks into the logits processor in Transformers.js, and the technical story behind it: from a WASM wrapper around llguidance to a pure JavaScript implementation with almost no overhead. Also in 4.3: a complete overhaul of the documentation pipeline and a bunch of community-contributed fixes and features. Thank you! Chapters 0:00 Transformers.js 4.3 is out 0:26 New documentation pipeline 1:00 Community contributions 1:19 The problem: unreliable JSON from LLMs 2:18 How constrained decoding works 3:25 Adding the structured output processor 3:37 The new packages folder and plugin approach 6:03 Using regex instead of JSON Schema 6:45 Demo: recipe generator 7:33 Behind the feature: llguidance 9:02 Rewriting it in pure JavaScript 9:22 Performance across Gemma 4, Granite and LFM 2.5 10:26 Try it out Links Release notes: https://github.com/huggingface/transformers.js/releases/tag/4.3.0 NPM: https://www.npmjs.com/package/@huggingface/transformers/v/4.3.0 Structured output package: https://www.npmjs.com/package/@huggingface/transformers-structured-output