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

# Bootstrap a Taxonomy with AI

> Use AI to automatically generate domain-specific taxonomies for your documents

This cookbook shows you how to use the platform's AI to automatically generate custom taxonomies. Instead of manually defining tags one by one, you can describe your use case in natural language, and the AI will build a complete taxonomy for you.

## AI-Generated Taxonomies

The `suggest` feature allows you to bootstrap complex taxonomies in seconds:

```python theme={"dark"}
from unstructured import UnstructuredClient

client = UnstructuredClient(
    base_url="https://unstructured.your-company.com/rest/unstructured",
    username="your-username",
    password="your-password",
)

# Describe what you want to extract. The AI grounds its suggestions
# in the actual documents behind the data connector.
suggestions = client.taxonomy.suggest(
    data_connector_name="my-documents",
    user_context="""
    I need to analyze legal contracts. Extract key terms, financial obligations, 
    risk indicators, important dates, and anything relevant for compliance.
    Focus on NDAs, MSAs, and employment agreements.
    """,
    taxonomy_name="legal-contracts",
)

# Review the suggestions
print("🤖 AI-Suggested Taxonomy:")
print(suggestions.suggestion)
```

**Example output:**

```
🤖 AI-Suggested Taxonomy:
{
  "contract_type": {
    "description": "Primary contract classification: NDA, MSA, SLA, SOW, Employment, Lease",
    "type": "string"
  },
  "parties": {
    "description": "All parties to the contract with their legal names",
    "type": "string"
  },
  "effective_date": {
    "description": "Date when the contract becomes legally binding",
    "type": "date"
  },
  "total_value": {
    "description": "Total monetary value of the contract in USD",
    "type": "number"
  }
}
```

## Save the Taxonomy

Pass `auto_save=True` to store the suggested taxonomy directly, or review it first and create the tags yourself:

```python theme={"dark"}
# Option A: save the suggestion in one call
client.taxonomy.suggest(
    data_connector_name="my-documents",
    user_context="Analyze legal contracts for compliance",
    taxonomy_name="legal-contracts",
    auto_save=True,
)

# Option B: review, then create tags from the suggestion
for name, details in suggestions.suggestion.items():
    client.tags.upsert(tag_data={
        "name": name,
        "description": details["description"],
        "output_type": details["type"],
    })
```

## Refine with Sample Documents

For higher accuracy, point to specific files in your data connector. The AI will analyze these documents to suggest relevant tags:

```python theme={"dark"}
# The AI analyzes your files to suggest the most relevant tags
suggestions = client.taxonomy.suggest(
    data_connector_name="my-s3-bucket",
    user_context="Extract key data from these vendor invoices",
    file_names=[
        "invoices/sample-invoice-1.pdf",
        "invoices/sample-invoice-2.pdf"
    ]
)
```

## Customize the Results

You can modify the AI suggestions before creating the tags:

```python theme={"dark"}
# Get suggestions
response = client.taxonomy.suggest(
    data_connector_name="my-docs",
    user_context="Legal contract analysis",
)

# Create tags from the suggestion
for name, details in response.suggestion.items():
    client.tags.upsert(tag_data={
        "name": name,
        "description": details["description"],
        "output_type": details["type"],
    })

# Add a custom tag the AI might have missed
client.tags.upsert(tag_data={
    "name": "reviewed_by_legal",
    "description": "Whether this contract has been reviewed",
    "output_type": "binary",
})
```

## Common Use Cases

<Tabs>
  <Tab title="Financial Reports">
    ```python theme={"dark"}
    client.taxonomy.suggest(
        user_context="""
        Analyze quarterly financial reports. Extract revenue, earnings, 
        growth metrics, risk factors, and forward guidance.
        """,
        data_connector_name="finance-docs"
    )
    ```
  </Tab>

  <Tab title="Resumes">
    ```python theme={"dark"}
    client.taxonomy.suggest(
        user_context="""
        Process resumes for technical recruiting. Extract skills, 
        experience level, education, and certifications.
        """,
        data_connector_name="hr-docs"
    )
    ```
  </Tab>

  <Tab title="Insurance Claims">
    ```python theme={"dark"}
    client.taxonomy.suggest(
        user_context="""
        Analyze insurance claims. Extract claim details, incident info, 
        injury status, and potential fraud indicators.
        """,
        data_connector_name="claims-docs"
    )
    ```
  </Tab>
</Tabs>

## Next Steps

<CardGroup cols={2}>
  <Card title="Organize a SharePoint Library" icon="microsoft" href="/cookbooks/sharepoint-to-sharepoint">
    Enrich libraries at the source with your taxonomy.
  </Card>

  <Card title="Clean Up a RAG Index" icon="database" href="/cookbooks/qdrant-to-qdrant">
    Curate a serving collection with your taxonomy.
  </Card>

  <Card title="Protect Sensitive Data" icon="shield" href="/cookbooks/pii-detection">
    Add sensitive data detection.
  </Card>

  <Card title="Taxonomies Concept" icon="tags" href="/concepts/taxonomies-tags">
    Learn the fundamentals of taxonomies.
  </Card>
</CardGroup>
