Skip to content

JSON extraction

Fine-tune an LLM for JSON extraction and structured output

Fine-tune an open model to pull fields out of invoices, forms and emails as JSON that matches your schema, and score it field by field.

The problem

Why does extraction need a fine-tuned model?

A general model asked for JSON can name a field one way on one request and another way on the next. It can also put the JSON inside a sentence or a code block, and the code that parses the answer then fails.

Your code needs the same fields, with the same names and types, on every document. A model fine-tuned on your documents and the JSON you expect from each is trained to answer that way, and you can measure how often it does before you publish it.

How it works

How Tensorant trains and checks JSON

  • A Structured JSON recipe writes examples from your documents, each answered with JSON for your schema. The schema is JSON Schema draft 2020-12, written inline, without $ref, pattern or format. In Review, an example it wrote can be approved only when its answer matches the schema.
  • Structured JSON scoring records JSON-schema correctness, whether each answer is valid JSON that matches the schema. For the fields you list as paths, such as /total, it also records JSON field accuracy, the share of those fields whose value matches the reference.
  • When you call the published model, response_format with a JSON schema makes it answer in JSON that matches the schema. An answer cut off at max_tokens can hold incomplete JSON, so check that finish_reason is stop. See Response format.

Models

Models to start with

Start with a small instruct model that answers directly. Every family Tensorant trains is in Supported models.

  • Qwen/Qwen3-4B-Instruct-2507

    A 4B instruct model that answers directly, without a reasoning block, so its answer can be the JSON alone.

  • mistralai/Mistral-7B-Instruct-v0.3

    A larger model to try if a 4B model misses fields on your test set.

  • unsloth/Llama-3.2-1B-Instruct

    An ungated copy of Llama 3.2 1B Instruct. It needs the least GPU memory of these three.

See every supported model

Steps

How to do it in Tensorant

  1. Create a project

    Choose a base model and the Extraction to JSON use case. The project then offers the Structured JSON recipe and Structured JSON scoring first.

  2. Import or generate examples

    Import examples you already have, each a document's text as the question and the JSON you expect as the answer, in question and answer columns or as conversations. See Sources. To write examples from your documents instead, save a Structured JSON recipe with your schema and generate examples with a model endpoint or a deployment.

  3. Review against the schema

    Approve the examples in Review, and fix or reject any answer that doesn't match the schema. Then create a version, which holds its test examples out for scoring.

  4. Run an experiment

    An experiment scores the base model, trains an adapter and scores the adapter on the same test examples. Score it as Structured JSON, with your schema and the fields to compare.

  5. Publish it and call it

    Give the adapter a name in API models and send requests with response_format set to your JSON schema. See the API quickstart.

Plans

What you need

  • Text fine-tuning, evaluations and publishing are on every organization, with the same limits for all. Each training run pays a training-token fee from credits. See Limits on every organization.
  • GPUs come from Tensorant compute, charged per second from prepaid credits, which an owner adds under Settings, Plan and billing (the first payment turns Tensorant compute on), or from a GPU account you connect with the Own compute subscription. See connections.
  • Generating examples with a recipe sends your documents to the model endpoint you choose, and its provider bills you for the requests. See what is sent to the endpoint.

Guides

Related guides

Browse all guides

Use cases

Other use cases

See every use case

Start with one dataset.

Create an account and import your data, or book a demo and we will show you the product.