> For the complete documentation index, see [llms.txt](https://docs.datapancake.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.datapancake.com/core-concepts/attribute-metadata/attribute-discovery-process.md).

# Attribute Discovery Process

How DataPancake discovers attributes during scanning, including polymorphic detection and recursive parsing of stringified JSON.

## Discovery Process

1. **Recursively traverse records** - Every nested level is visited
2. **Track attribute paths** - Complete paths from root to leaf (e.g., `customer.contact.email`)
3. **Identify data types** - Source data type inferred for each path occurrence
4. **Create all 7 polymorphic versions** - Proactively created when attribute first discovered
5. **Activate matching versions** - Only versions matching discovered types set to `VERSION_STATUS = 'active'`
6. **Create attribute records** - Records created in `core.datasource_attribute` and `core.datasource_attribute_polymorphic_version`

***

## What Gets Discovered

* **All attribute paths** - Complete paths from root to leaf (e.g., `customer.contact.email`)
* **Nested objects** - Every level of object nesting
* **Nested arrays** - Both object arrays (`ARRAY_TYPE = 'object'`) and primitive arrays (`ARRAY_TYPE = 'primitive'`)
* **Embedded JSON** - JSON stored as strings (`HAS_EMBEDDED_CONTENT = TRUE`); recursively parsed
* **Polymorphic variations** - All data type variations for the same path (handled via polymorphic versions)

***

## Example: Polymorphic Discovery

**Record 1:**

```json
{
  "customer_id": "C001",
  "customer": {
    "address": "123 Main St, Anytown, ST 12345",
    "metadata": "{\"source\":\"web\",\"tags\":[\"vip\"]}"
  }
}
```

**Record 2:**

```json
{
  "customer_id": "C002",
  "customer": {
    "address": {"street": "456 Oak Ave", "city": "Springfield"},
    "metadata": "{\"source\":\"mobile\",\"tags\":[\"new\"]}"
  }
}
```

**Discovery Results:**

* `customer.address`:
  * Record 1: `str` → `address_str` activated
  * Record 2: `object` → `address_object` activated (existing version)
* `customer.metadata`:
  * `HAS_EMBEDDED_CONTENT = TRUE`
  * Recursively parsed to discover: `metadata.source`, `metadata.tags[]`


---

# 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.datapancake.com/core-concepts/attribute-metadata/attribute-discovery-process.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.
