> ## Documentation Index
> Fetch the complete documentation index at: https://developer.kodexa.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Building Data Classes

> Build Python data classes from Kodexa Data Definitions to apply business rules, validation, and transformations to extracted document data programmatically.

One of the key aspects of working with Data Definitions and extraction models is the ability to build Python data classes. These classes let you take the structured output bound to a document and apply business rules to it.

This is a powerful way in which you can work with the Kodexa LLM Data Labeling models.

If you look at an LLM Data Labeling model in a pipeline (in Manage Project / Data Flows) you will see on the options you can set the external data. This will store the data captured by the LLM in a special format that includes lineage to the document.

<img src="https://mintcdn.com/kodexa/fcSOqm-7T1yIp0A8/concepts/images/BDC1.png?fit=max&auto=format&n=fcSOqm-7T1yIp0A8&q=85&s=574b9dc30afb99d4be67235f5aa86bc7" alt="Building Data Classes 1" width="1170" height="632" data-path="concepts/images/BDC1.png" />

You can then use this structure if you want to apply rules or transform it.

To do this we can use the Kodexa Python SDK. Install it with `pip install kodexa`.

If you go to your project and find the Data Definition used by your LLM model, Developer Tools gives you a copy action for the JSON representation of that definition.

<img src="https://mintcdn.com/kodexa/fcSOqm-7T1yIp0A8/concepts/images/BDC2.png?fit=max&auto=format&n=fcSOqm-7T1yIp0A8&q=85&s=156395ed799796cdf03e5a5598605b08" alt="Building Data Classes 2" width="1130" height="824" data-path="concepts/images/BDC2.png" />

Then paste the content into a file. In this example, we will call it `data-definition.json`.

<img src="https://mintcdn.com/kodexa/fcSOqm-7T1yIp0A8/concepts/images/BDC3.png?fit=max&auto=format&n=fcSOqm-7T1yIp0A8&q=85&s=02867fe76d2ea0d91e4f31b2f1971bbf" alt="Building Data Classes 3" width="2272" height="1760" data-path="concepts/images/BDC3.png" />

If you have the Kodexa Python SDK installed, you can open a terminal and run the command:

```bash theme={null}
kodexa dataclasses data-definition.json
```

This will create a `dataclasses.py` file that will contain the structure of the objects.

<img src="https://mintcdn.com/kodexa/fcSOqm-7T1yIp0A8/concepts/images/BDC4.png?fit=max&auto=format&n=fcSOqm-7T1yIp0A8&q=85&s=cdef556b249c2bcc4c74ba63da37f4aa" alt="Building Data Classes 4" width="2272" height="1760" data-path="concepts/images/BDC4.png" />

<Tip>
  Always rename `dataclasses.py` since it might clash with the system package.
</Tip>

You can now use the dataclasses to read the data that was set in your model in external data, for example:

```python theme={null}
def infer(document):
	
	bank_statement = document.get_external_data()['bank_statement'][0]
```

If you wish to change a value, always update the normalized\_text not the value.
