← Examples

Text to JSON

Extraction into a schema you write. Kiln's grammar enforces the schema at every token, so the result always parses and fits.

Qwen2.5-0.5B-Instruct


The code

llm.chat(messages, { format: { type: "json", schema } }); // always valid against schema

Full source: site/src/examples/structured.ts