> For the complete documentation index, see [llms.txt](https://docs.sdv.dev/sdv/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.sdv.dev/sdv/integration/metadata/data-lineage.md).

# Data Lineage

SDV's metadata object includes basic structural elements of a database that are typically found in a schema definition. For example:

* The type of data in each column
* The primary key of each table (or composite keys if you have them)
* Foreign keys that reference primary keys of other tables

However, you may have other rules in your dataset that are the result of data moving and evolving over time (part of data lineage flow). For example, only certain types of primary keys are allowed to be referenced from another table, as illustrated below.

<figure><img src="/files/pAszJeFgbSqxH1xTmg5X" alt=""><figcaption><p>Data lineage rules dictate that only accounts that are type "Premium" are allowed to have perks. That means that the foreign key from Perks can only reference a subset of Accounts.</p></figcaption></figure>

## Add data lineage rules as constraints

Data lineage rules cannot be added to the metadata, but they can be incorporated later into SDV's modeling step. When modeling, you can **automatically detect data lineage rules** as constraints and **add them to your synthesizer**. This ensures that the synthetic data you generate always adheres to the data lineage rules that are part of your dataset.

```python
from sdv.multi_table import HSASynthesizer

synthesizer = HSASynthesizer(metadata)

# detect data lineage logic as constraints
detected_constraints = synthesizer.detect_constraints(data)
synthesizer.add_constraints(detected_constraints)

# now the synthetic data includes data lineage rules
synthesizer.fit(data)
synthetic_data = synthesizer.sample()
```

For more information about constraints, please see the [Constraint-Augmented Generation](/sdv/modeling/constraint-augmented-generation-cag.md) docs.


---

# 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 dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.sdv.dev/sdv/integration/metadata/data-lineage.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
