> 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/evaluation/diagnostic.md).

# Diagnostic

Diagnostic checks are meant to validate the basic data format and validity of the synthetic data. Run through these to make sure that the basics are met. We expect the score to be a perfect, 100%.

## Diagnostic Report

We recommend running the Diagnostic Report to run all basic checks for data format and validity on your synthetic data at once.

### run\_diagnostic

Use this function to run a diagnostic on the synthetic data.

```python
from sdv.evaluation import run_diagnostic

diagnostic_report = run_diagnostic(
    real_data=real_data,
    synthetic_data=synthetic_data,
    metadata=metadata)
```

```
Generating report ...

(1/3) Evaluating Data Validity: |██████████| 15/15 [00:00<00:00, 603.69it/s]|
Data Validity Score: 100.0%

(2/3) Evaluating Data Structure: |██████████| 2/2 [00:00<00:00, 151.49it/s]|
Data Structure Score: 100.0%

(3/3) Evaluating Relationship Validity: |██████████| 1/1 [00:00<00:00, 68.51it/s]|
Relationship Validity Score: 100.0%

Overall Score (Average): 100.0%
```

**Parameters**:

* (required) `real_data`: The original training data. *For single table data, this is a pandas.DataFrame. For multi table data, this is a dictionary mapping each table name (string) to a pandas.DataFrame containing the data.*
* (required) `synthetic_data`: Your synthetic data. *For single table data, this is a pandas.DataFrame. For multi table data, this is a dictionary mapping each table name (string) to a pandas.DataFrame containing the data.*
* (required) `metadata`: A [Metadata](/sdv/integration/metadata.md) object with your metadata
* `verbose`: A boolean describing whether or not to print the report progress and results. Defaults to `True`. Set this to `False` to run the report silently.

**Returns**: An [SDMetrics DiagnosticReport](https://docs.sdv.dev/sdmetrics/data-metrics/diagnostic/diagnostic-report) object generated with your real and synthetic data

### Interpreting the Score

{% hint style="success" %}
**The score should be 100%.** The diagnostic report checks for basic data validity and data structure issues. You should expect the score to be perfect for any of the default SDV synthesizers.
{% endhint %}

The basic diagnostic checks are summarized in the table below.

<table><thead><tr><th width="158">Property</th><th>Description</th></tr></thead><tbody><tr><td>Data Validity</td><td><p>Basic validity checks for each of the columns:</p><ol><li>Primary keys must always be unique and non-null</li><li>Continuous values in the synthetic data must adhere to the min/max range in the real data</li><li>Discrete values in the synthetic data must adhere to the same categories as the real data.</li><li>ID columns must adhere to the provided Regex format.</li><li>Datetime columns must adhere to the provided datetime format.</li></ol></td></tr><tr><td>Structure</td><td>Checks to ensure the real and synthetic data have the same column names</td></tr><tr><td>Relationship Validity</td><td><p><em>For multi-table data only.</em> Basic validity checks for each relationship between a parent table and a child table:</p><ol><li>Each primary key in the parent table must have an appropriate number of children (i.e. cardinality) based on the min/max of the real data.</li><li>Each foreign key in the child table must reference a primary key that exists in the parent (i.e. referential integrity).</li></ol></td></tr></tbody></table>

### get\_details

This function returns details about the report's properties. Use it to pinpoint the exact columns or tables that are causing issues.

**Parameters**:

* (required) `property_name`: A string with the name of the property. One of: `'Data Validity'`, `'Structure'`, or `'Relationship Validity'`
* `table_name`: For multi table data, a string with the name of the table. If provided, you'll receive filtered results for the table.

**Returns** A pandas.DataFrame object with the detailed scores

```python
diagnostic_report.get_details(property_name='Data Validity')
```

```python
Table     Column	        Metric                   Score
guests    guest_email     KeyUniqueness            1.0
guests    had_rewards     CategoryAdherence	       1.0
guests    room_type       CategoryAdherence	       1.0
guests    amenities_fee   BoundaryAdherence	       1.0
```

## Utilities

### print\_referential\_integrity

Use this function to manually check for referential integrity across a few randomly-selected values from the synthetic data. This is useful for demo purposes.

*To run a full referential integrity check for all values across all relationships, we recommend running the* [*Diagnostic Report*](#diagnostic-report) *instead.*

```python
from sdv.evaluation.utils import print_referential_integrity

print_referential_integrity(
  metadata=metadata,
  synthetic_data=synthetic_data,
  table_name='transaction',
  foreign_key_name='user_id',
  num_rows=3
)
```

```
Picking random transaction row: 1468732365
✅ Found user row! user_id: 86-25-19730100-15 

Picking random transaction row: 1988317645
✅ Found user row! user_id: 0-35-79964375-26 

Picking random transaction row: 1507984147
❌ Unable to find the linked user row
```

**Parameters**:

* (required) `metadata`: The [metadata](/sdv/integration/metadata.md) object that corresponds to your data schema.
* (required) `synthetic_data`: A dictionary that maps each table name to a pandas.DataFrame containing the synthetic data for it
* (required) `table_name`: A string containing the table name that has the foreign key to check
* (required)  `foreign_key_name`: A string with the column of the foreign key to check. For composite keys, provide a tuple of strings.
* `num_rows`: An int containing the number of columns to check; defaults to 10.

**Returns**: None. The function chooses a few foreign key values random from the synthetic data and checks to make sure the references are found in the parent table. It prints out the result for each column.


---

# 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/evaluation/diagnostic.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.
