> For the complete documentation index, see [llms.txt](https://docs.mindee.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.mindee.com/classification-models/extraction-model-chaining.md).

# Extraction Model Chaining

Selectively extract data from detected classes.

Link a Classification model to one or more [Extraction Models](/extraction-models/extraction-models-overview.md), to automatically extract structured data from documents based on their detected class.

Note: Classification Models always return a single class regardless of the number of pages or if there are multiple documents on the same page.

## Extraction Set Up

### At Model Creation

When creating your Classification Model, you'll be adding document classes in the creation window.

For each document class, you can link one of your Extraction Models for chaining. The Extraction Model must exist prior to the Classification Model creation.

Use the search field to filter available Extraction Models.

### After Model Creation

This works exactly like when creating at model creation.

Simply go to your Split model's "Utility Configuration" page and adjust as needed.

You can add new classes, remove classes, and change Extraction Models.

### Selectively Extracting

All documents will get classified, but only those linked to an Extraction Model will have extraction results.

This allows selectively extracting some files while ignoring others.

{% hint style="info" icon="lightbulb" %}
Add an `other` class in addition to classes of interest to you, unless all potential document types are known in advance.
{% endhint %}

### Putting It All Together

As a sample use case, let's say you have a KYC workflow, and your users upload their files. As a result, you receive mixed file types in the pipeline: driver licenses, passports, student IDs, employee badges, social security cards, etc.

As a first example, assume you only process passports. In your Classification configuration, add a `passport` class and an `other`  class, then chain a [Passport extraction model](/use-cases/extraction-models/passport.md) on the `passport` class. Do not chain any models on the `other` class.

Another example, if you need only government IDs (so driver license and passport), you have two choices:

* Create an `official_government_id` class and chain it to an [International ID extraction model](/use-cases/extraction-models/international-id-card.md).\
  This is recommended if you accept a variety of ID documents.
* Create a `driving_license` and `passport` class and chain the [Driver's License](/use-cases/extraction-models/drivers-license.md) and [Passport](/use-cases/extraction-models/passport.md) extraction models to them, respectively.\
  This is recommended if you only accept specific ID documents.

As in the earlier example, do not chain any models on the `other` class.

In the above examples, the documents classified as `other` will **not** have extraction results, while those with specific classes **will** have results.

You can of course use **any** extraction model, including fully custom ones.

## Token Usage With Chaining

The initial model (Split, Crop, Classification) is provided at no additional cost to you if it triggers additional processing using an Extraction model.

The possible credit consumption scenarios are as follows:

* extraction model not chained ⇒ token usage of initial model
* extraction models chained ⇒ token usage of the extraction model, including any activated [optional features](/extraction-models/optional-features.md).

Token consumption is calculated per page as is standard for our models.

For Classification models specifically, there can be only a single chained extraction per file. This means that the total number of pages processed by an Extraction model will be always equal to the number of pages in the source document.

Some examples:

* JPEG image file, a document is detected and chained ⇒ 1 page of Extraction credit consumed.
* 23-page PDF file, a document is detected and chained ⇒ 23 pages of Extraction credit consumed.
* PNG image file, no document detected ⇒ 1 page of Classification credit consumed.
* 75-page PDF file, a document is detected but **not** chained ⇒ 75 pages of Classification credit consumed.

## Access Extraction Results

When an Extraction Model is linked, the detected class contains an Extraction Response object.

That object is the same as the response returned by a standalone Extraction request.

Check [Classification Result](/classification-models/sdk-integration/classification-result.md) for details on accessing crop items and their extraction responses.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.mindee.com/classification-models/extraction-model-chaining.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
