> ## 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.

# Generate from Context

> Generate a taxonomy structure from user-provided context using AI.

This endpoint allows users to describe their data and use case, and the system will
generate an appropriate taxonomy structure (hierarchical or flat) without requiring
actual data files.

## Request Body

| Field              | Type             | Description                                                          |
|--------------------|------------------|----------------------------------------------------------------------|
| `user_context`     | `str`            | Free-form description of the data and intended use                   |
| `industry`         | `Optional[str]`  | Industry context (e.g., "Healthcare", "Finance", "Legal")            |
| `data_type`        | `Optional[str]`  | Type of data (e.g., "documents", "customer records")                 |
| `use_case`         | `Optional[str]`  | Specific use case description                                        |
| `taxonomy_type`    | `str`            | Type of taxonomy: "hierarchical" or "flat". Default: "hierarchical"  |
| `max_depth`        | `Optional[int]`  | Maximum depth for hierarchical taxonomies. Default: 3                |
| `llm_profile_name` | `Optional[str]`  | LLM profile to use. Defaults to system default if not specified      |

## Response

- **200**: Taxonomy generated successfully  
    - Returns: `{ "taxonomy_data": Dict, "taxonomy_description": str }`
- **400**: Invalid request or LLM configuration error
- **500**: Internal Server Error

## Example

```json
{
  "user_context": "I have customer support tickets with priority levels, categories, and resolution status",
  "industry": "Technology",
  "data_type": "support tickets",
  "use_case": "categorize and analyze support requests",
  "taxonomy_type": "hierarchical",
  "max_depth": 3
}
```



## OpenAPI

````yaml /deasy-openapi-stainless.yml post /taxonomy/generate_from_context
openapi: 3.1.0
info:
  title: FastAPI
  version: 0.1.0
servers:
  - url: /rest/unstructured
security: []
paths:
  /taxonomy/generate_from_context:
    post:
      tags:
        - Taxonomies
      summary: Generate from Context
      description: >-
        Generate a taxonomy structure from user-provided context using AI.


        This endpoint allows users to describe their data and use case, and the
        system will

        generate an appropriate taxonomy structure (hierarchical or flat)
        without requiring

        actual data files.


        ## Request Body


        | Field              | Type             |
        Description                                                          |

        |--------------------|------------------|----------------------------------------------------------------------|

        | `user_context`     | `str`            | Free-form description of the
        data and intended use                   |

        | `industry`         | `Optional[str]`  | Industry context (e.g.,
        "Healthcare", "Finance", "Legal")            |

        | `data_type`        | `Optional[str]`  | Type of data (e.g.,
        "documents", "customer records")                 |

        | `use_case`         | `Optional[str]`  | Specific use case
        description                                        |

        | `taxonomy_type`    | `str`            | Type of taxonomy:
        "hierarchical" or "flat". Default: "hierarchical"  |

        | `max_depth`        | `Optional[int]`  | Maximum depth for hierarchical
        taxonomies. Default: 3                |

        | `llm_profile_name` | `Optional[str]`  | LLM profile to use. Defaults
        to system default if not specified      |


        ## Response


        - **200**: Taxonomy generated successfully  
            - Returns: `{ "taxonomy_data": Dict, "taxonomy_description": str }`
        - **400**: Invalid request or LLM configuration error

        - **500**: Internal Server Error


        ## Example


        ```json

        {
          "user_context": "I have customer support tickets with priority levels, categories, and resolution status",
          "industry": "Technology",
          "data_type": "support tickets",
          "use_case": "categorize and analyze support requests",
          "taxonomy_type": "hierarchical",
          "max_depth": 3
        }

        ```
      operationId: generate_taxonomy_from_context_route_taxonomy_generate_from_context_post
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/GenerateTaxonomyFromContextRequest'
        required: true
      responses:
        '200':
          description: Successful Response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/GenerateTaxonomyFromContextResponse'
        '403':
          description: Missing token
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HTTPError'
        '404':
          description: Resource not found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HTTPError'
        '422':
          description: Validation Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HTTPValidationError'
        '429':
          description: Too many requests
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HTTPError'
        '500':
          description: >-
            Internal Server Error. An unexpected error occurred while processing
            the request.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HTTPError'
      security:
        - BasicAuth: []
        - BearerAuth: []
          UserIdAuth: []
      x-codeSamples:
        - lang: Python
          source: |-
            import os
            from unstructured import UnstructuredClient

            client = UnstructuredClient(
                username=os.environ.get("UNSTRUCTURED_USERNAME"),  # This is the default and can be omitted
                password=os.environ.get("UNSTRUCTURED_PASSWORD"),  # This is the default and can be omitted
            )
            response = client.taxonomy.generate_from_context(
                user_context="user_context",
            )
            print(response.taxonomy_data)
        - lang: JavaScript
          source: >-
            import UnstructuredClient from 'unstructured-sdk';


            const client = new UnstructuredClient({
              authMethod: 'My Auth Method',
              username: process.env['UNSTRUCTURED_USERNAME'], // This is the default and can be omitted
              password: process.env['UNSTRUCTURED_PASSWORD'], // This is the default and can be omitted
            });


            const response = await client.taxonomy.generateFromContext({
            user_context: 'user_context' });


            console.log(response.taxonomy_data);
components:
  schemas:
    GenerateTaxonomyFromContextRequest:
      properties:
        user_context:
          type: string
          title: User Context
        taxonomy_name:
          anyOf:
            - type: string
            - type: 'null'
          title: Taxonomy Name
        industry:
          anyOf:
            - type: string
            - type: 'null'
          title: Industry
        data_type:
          anyOf:
            - type: string
            - type: 'null'
          title: Data Type
        use_case:
          anyOf:
            - type: string
            - type: 'null'
          title: Use Case
        taxonomy_type:
          type: string
          title: Taxonomy Type
          default: hierarchical
        max_depth:
          anyOf:
            - type: integer
            - type: 'null'
          title: Max Depth
          default: 3
        llm_profile_name:
          anyOf:
            - type: string
            - type: 'null'
          title: Llm Profile Name
        data_connector_name:
          anyOf:
            - type: string
            - type: 'null'
          title: Data Connector Name
        validate_tags:
          anyOf:
            - type: boolean
            - type: 'null'
          title: Validate Tags
          default: false
      type: object
      required:
        - user_context
      title: GenerateTaxonomyFromContextRequest
    GenerateTaxonomyFromContextResponse:
      properties:
        taxonomy_data:
          type: object
          title: Taxonomy Data
        taxonomy_description:
          anyOf:
            - type: string
            - type: 'null'
          title: Taxonomy Description
        suggested_tags:
          anyOf:
            - type: object
            - type: 'null'
          title: Suggested Tags
        tag_not_found_rates:
          anyOf:
            - additionalProperties:
                type: number
              type: object
            - type: 'null'
          title: Tag Not Found Rates
      type: object
      required:
        - taxonomy_data
      title: GenerateTaxonomyFromContextResponse
    HTTPError:
      properties:
        detail:
          type: string
          title: Detail
      type: object
      required:
        - detail
      title: HTTPError
    HTTPValidationError:
      properties:
        detail:
          items:
            $ref: '#/components/schemas/ValidationError'
          type: array
          title: Detail
      type: object
      title: HTTPValidationError
    ValidationError:
      properties:
        loc:
          items:
            anyOf:
              - type: string
              - type: integer
          type: array
          title: Location
        msg:
          type: string
          title: Message
        type:
          type: string
          title: Error Type
      type: object
      required:
        - loc
        - msg
        - type
      title: ValidationError
  securitySchemes:
    BasicAuth:
      type: http
      scheme: basic
    BearerAuth:
      type: http
      scheme: bearer
    UserIdAuth:
      type: apiKey
      in: header
      name: X-User-ID

````