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

# Upsert

> Deprecated: use `POST /v2/tags` to create,
`PATCH /v2/tags/{tag_id}` to update.

Insert or update a tag definition.

## Request Body

| Field      | Type            | Description                                      |
|------------|-----------------|--------------------------------------------------|
| `tag_data` | `Tag` | Tag data structure containing tag definition.    |

## Response

- **200**: Tag upserted successfully
    - Returns: `{ "tag_name": str, "tag": Tag, "available_values_added": List[str] }`
- **400**: Bad Request (e.g., invalid tag data)
- **403**: Forbidden (e.g., tag is a read-only out-of-the-box tag)
- **500**: Internal Server Error

## Example

```json
{
  "tag_data": {
    "name": "category",
    "description": "Document category classification",
    "type": "select",
    "available_values": ["invoice", "receipt", "contract"]
  }
}
```



## OpenAPI

````yaml /deasy-openapi.yml post /tags/upsert
openapi: 3.1.0
info:
  title: Collibra Unstructured API
  description: >
    REST API for Collibra Unstructured.


    ## Authentication


    Every endpoint accepts either HTTP Basic credentials, or a bearer token sent
    together with the

    `X-User-ID` header identifying the user the call runs as.


    ## Base URL


    Your Unstructured deployment, for example
    `https://unstructured.your-company.com/rest/unstructured`.
  version: 0.1.14
servers:
  - url: /rest/unstructured
security:
  - BasicAuth: []
  - BearerAuth: []
    UserIdAuth: []
tags:
  - name: Core
    description: Endpoints for core functionality
  - name: Data
    description: Endpoints for source data
  - name: Metadata
    description: Endpoints for metadata management
  - name: Tags
    description: Endpoints for tag management
  - name: Taxonomy
    description: Endpoints for taxonomy management
  - name: Dataslice
    description: Endpoints for dataslice management
  - name: Progress Tracker
    description: Endpoints for tracking progress
  - name: Classification
    description: Endpoints for classification
  - name: Ingestion
    description: Endpoints for document ingestion
  - name: Workflows
    description: Endpoints for workflow management
  - name: Deduplication
    description: Endpoints for deduplication
paths:
  /tags/upsert:
    post:
      tags:
        - Tags
      summary: Upsert
      description: >-
        Deprecated: use `POST /v2/tags` to create,

        `PATCH /v2/tags/{tag_id}` to update.


        Insert or update a tag definition.


        ## Request Body


        | Field      | Type            |
        Description                                      |

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

        | `tag_data` | `Tag` | Tag data structure containing tag definition.   
        |


        ## Response


        - **200**: Tag upserted successfully
            - Returns: `{ "tag_name": str, "tag": Tag, "available_values_added": List[str] }`
        - **400**: Bad Request (e.g., invalid tag data)

        - **403**: Forbidden (e.g., tag is a read-only out-of-the-box tag)

        - **500**: Internal Server Error


        ## Example


        ```json

        {
          "tag_data": {
            "name": "category",
            "description": "Document category classification",
            "type": "select",
            "available_values": ["invoice", "receipt", "contract"]
          }
        }

        ```
      operationId: upsert_tag_route_tags_upsert_post
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/UpsertTagRequest'
        required: true
      responses:
        '200':
          description: Successful Response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/UpsertTagResponse'
        '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'
      deprecated: true
      x-codeSamples:
        - lang: Python
          source: |
            # pip install deasy-sdk
            import os
            from deasy import DeasyClient

            client = DeasyClient(
                base_url=os.environ["UNSTRUCTURED_CLIENT_BASE_URL"],
                username=os.environ["UNSTRUCTURED_USERNAME"],
                password=os.environ["UNSTRUCTURED_PASSWORD"],
            )

            response = client.tags.upsert(
                tag_data={
                    "name": "example_name",
                },
            )
            print(response.tag_name)
components:
  schemas:
    UpsertTagRequest:
      properties:
        tag_data:
          $ref: '#/components/schemas/Tag-Input'
      type: object
      required:
        - tag_data
      title: UpsertTagRequest
    UpsertTagResponse:
      properties:
        tag_name:
          type: string
          title: Tag Name
        tag:
          $ref: '#/components/schemas/Tag-Output'
        available_values_added:
          items:
            type: string
          type: array
          title: Available Values Added
      type: object
      required:
        - tag_name
        - tag
        - available_values_added
      title: UpsertTagResponse
    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
    Tag-Input:
      properties:
        tag_id:
          anyOf:
            - type: string
            - type: 'null'
          title: Tag Id
        username:
          anyOf:
            - type: string
            - type: 'null'
          title: Username
        principal_id:
          anyOf:
            - type: string
            - type: 'null'
          title: Principal Id
        name:
          type: string
          title: Name
        description:
          anyOf:
            - type: string
            - type: 'null'
          title: Description
          default: ''
        output_type:
          anyOf:
            - $ref: '#/components/schemas/TagOutputType'
            - type: 'null'
          default: string
        available_values:
          anyOf:
            - items:
                anyOf:
                  - type: string
                  - type: number
                  - type: integer
              type: array
            - type: 'null'
          title: Available Values
          default: []
        examples:
          anyOf:
            - items:
                anyOf:
                  - type: string
                  - additionalProperties: true
                    type: object
              type: array
            - type: 'null'
          title: Examples
          default: []
        created_at:
          anyOf:
            - type: string
              format: date-time
            - type: 'null'
          title: Created At
        updated_at:
          anyOf:
            - type: string
              format: date-time
            - type: 'null'
          title: Updated At
        tuned:
          anyOf:
            - type: integer
            - type: 'null'
          title: Tuned
          default: 0
        maxValues:
          anyOf:
            - type: integer
            - type: string
            - items: {}
              type: array
            - type: 'null'
          title: Maxvalues
        neg_examples:
          anyOf:
            - items:
                type: string
              type: array
            - type: 'null'
          title: Neg Examples
          default: []
        retry_feedback:
          anyOf:
            - additionalProperties: true
              type: object
            - type: 'null'
          title: Retry Feedback
        date_format:
          anyOf:
            - type: string
            - type: 'null'
          title: Date Format
        strategy:
          anyOf:
            - type: string
            - type: 'null'
          title: Strategy
          default: LLM
        scope:
          anyOf:
            - type: string
            - type: 'null'
          title: Scope
          default: ALL_PAGES
        truncated_available_values:
          anyOf:
            - type: boolean
            - type: 'null'
          title: Truncated Available Values
          default: false
        enhance_file_metadata:
          anyOf:
            - type: boolean
            - type: 'null'
          title: Enhance File Metadata
          default: true
        regex:
          anyOf:
            - type: string
            - type: 'null'
          title: Regex
        patterns:
          anyOf:
            - items:
                $ref: '#/components/schemas/RegexPattern'
              type: array
            - type: 'null'
          title: Patterns
          default: []
        visual_rules:
          anyOf:
            - items:
                $ref: '#/components/schemas/RuleBasedRule-Input'
              type: array
            - type: 'null'
          title: Visual Rules
          default: []
        run_dependent_tags:
          anyOf:
            - type: boolean
            - type: 'null'
          title: Run Dependent Tags
          default: false
        group:
          anyOf:
            - type: string
            - type: 'null'
          title: Group
        min_confidence:
          anyOf:
            - type: number
            - type: 'null'
          title: Min Confidence
        export_min_confidence:
          anyOf:
            - type: number
            - type: 'null'
          title: Export Min Confidence
        collibra_asset_id:
          anyOf:
            - type: string
            - type: 'null'
          title: Collibra Asset Id
        collibra_domain_id:
          anyOf:
            - type: string
            - type: 'null'
          title: Collibra Domain Id
        source_asset_type:
          anyOf:
            - type: string
            - type: 'null'
          title: Source Asset Type
        value_descriptions:
          anyOf:
            - additionalProperties:
                type: string
              type: object
            - type: 'null'
          title: Value Descriptions
        value_sources:
          anyOf:
            - additionalProperties:
                type: string
              type: object
            - type: 'null'
          title: Value Sources
        governance_metadata:
          anyOf:
            - $ref: '#/components/schemas/GovernanceMetadata'
            - type: 'null'
        origin:
          anyOf:
            - type: string
            - type: 'null'
          title: Origin
          default: manual
        curation_state:
          anyOf:
            - type: string
            - type: 'null'
          title: Curation State
        is_owner:
          anyOf:
            - type: boolean
            - type: 'null'
          title: Is Owner
        owner_name:
          anyOf:
            - type: string
            - type: 'null'
          title: Owner Name
        permissions:
          anyOf:
            - $ref: '#/components/schemas/TagPermissions'
            - type: 'null'
        avg_confidence:
          anyOf:
            - type: number
            - type: 'null'
          title: Avg Confidence
        usage:
          anyOf:
            - $ref: '#/components/schemas/TagUsage'
            - type: 'null'
        usage_stats_as_of:
          anyOf:
            - type: string
              format: date-time
            - type: 'null'
          title: Usage Stats As Of
        examples_count:
          anyOf:
            - type: integer
            - type: 'null'
          title: Examples Count
      type: object
      required:
        - name
      title: Tag
    Tag-Output:
      properties:
        tag_id:
          anyOf:
            - type: string
            - type: 'null'
          title: Tag Id
        username:
          anyOf:
            - type: string
            - type: 'null'
          title: Username
        principal_id:
          anyOf:
            - type: string
            - type: 'null'
          title: Principal Id
        name:
          type: string
          title: Name
        description:
          anyOf:
            - type: string
            - type: 'null'
          title: Description
          default: ''
        output_type:
          anyOf:
            - $ref: '#/components/schemas/TagOutputType'
            - type: 'null'
          default: string
        available_values:
          anyOf:
            - items:
                anyOf:
                  - type: string
                  - type: number
                  - type: integer
              type: array
            - type: 'null'
          title: Available Values
          default: []
        examples:
          anyOf:
            - items:
                anyOf:
                  - type: string
                  - additionalProperties: true
                    type: object
              type: array
            - type: 'null'
          title: Examples
          default: []
        created_at:
          anyOf:
            - type: string
              format: date-time
            - type: 'null'
          title: Created At
        updated_at:
          anyOf:
            - type: string
              format: date-time
            - type: 'null'
          title: Updated At
        tuned:
          anyOf:
            - type: integer
            - type: 'null'
          title: Tuned
          default: 0
        maxValues:
          anyOf:
            - type: integer
            - type: string
            - items: {}
              type: array
            - type: 'null'
          title: Maxvalues
        neg_examples:
          anyOf:
            - items:
                type: string
              type: array
            - type: 'null'
          title: Neg Examples
          default: []
        retry_feedback:
          anyOf:
            - additionalProperties: true
              type: object
            - type: 'null'
          title: Retry Feedback
        date_format:
          anyOf:
            - type: string
            - type: 'null'
          title: Date Format
        strategy:
          anyOf:
            - type: string
            - type: 'null'
          title: Strategy
          default: LLM
        scope:
          anyOf:
            - type: string
            - type: 'null'
          title: Scope
          default: ALL_PAGES
        truncated_available_values:
          anyOf:
            - type: boolean
            - type: 'null'
          title: Truncated Available Values
          default: false
        enhance_file_metadata:
          anyOf:
            - type: boolean
            - type: 'null'
          title: Enhance File Metadata
          default: true
        regex:
          anyOf:
            - type: string
            - type: 'null'
          title: Regex
        patterns:
          anyOf:
            - items:
                $ref: '#/components/schemas/RegexPattern'
              type: array
            - type: 'null'
          title: Patterns
          default: []
        visual_rules:
          anyOf:
            - items:
                $ref: '#/components/schemas/RuleBasedRule-Output'
              type: array
            - type: 'null'
          title: Visual Rules
          default: []
        run_dependent_tags:
          anyOf:
            - type: boolean
            - type: 'null'
          title: Run Dependent Tags
          default: false
        group:
          anyOf:
            - type: string
            - type: 'null'
          title: Group
        min_confidence:
          anyOf:
            - type: number
            - type: 'null'
          title: Min Confidence
        export_min_confidence:
          anyOf:
            - type: number
            - type: 'null'
          title: Export Min Confidence
        collibra_asset_id:
          anyOf:
            - type: string
            - type: 'null'
          title: Collibra Asset Id
        collibra_domain_id:
          anyOf:
            - type: string
            - type: 'null'
          title: Collibra Domain Id
        source_asset_type:
          anyOf:
            - type: string
            - type: 'null'
          title: Source Asset Type
        value_descriptions:
          anyOf:
            - additionalProperties:
                type: string
              type: object
            - type: 'null'
          title: Value Descriptions
        value_sources:
          anyOf:
            - additionalProperties:
                type: string
              type: object
            - type: 'null'
          title: Value Sources
        governance_metadata:
          anyOf:
            - $ref: '#/components/schemas/GovernanceMetadata'
            - type: 'null'
        origin:
          anyOf:
            - type: string
            - type: 'null'
          title: Origin
          default: manual
        curation_state:
          anyOf:
            - type: string
            - type: 'null'
          title: Curation State
        is_owner:
          anyOf:
            - type: boolean
            - type: 'null'
          title: Is Owner
        owner_name:
          anyOf:
            - type: string
            - type: 'null'
          title: Owner Name
        permissions:
          anyOf:
            - $ref: '#/components/schemas/TagPermissions'
            - type: 'null'
        avg_confidence:
          anyOf:
            - type: number
            - type: 'null'
          title: Avg Confidence
        usage:
          anyOf:
            - $ref: '#/components/schemas/TagUsage'
            - type: 'null'
        usage_stats_as_of:
          anyOf:
            - type: string
              format: date-time
            - type: 'null'
          title: Usage Stats As Of
        examples_count:
          anyOf:
            - type: integer
            - type: 'null'
          title: Examples Count
      type: object
      required:
        - name
      title: Tag
    ValidationError:
      properties:
        loc:
          items:
            anyOf:
              - type: string
              - type: integer
          type: array
          title: Location
        msg:
          type: string
          title: Message
        type:
          type: string
          title: Error Type
        input:
          title: Input
        ctx:
          type: object
          title: Context
      type: object
      required:
        - loc
        - msg
        - type
      title: ValidationError
    TagOutputType:
      type: string
      enum:
        - string
        - binary
        - number
        - date
      title: TagOutputType
    RegexPattern:
      properties:
        pattern:
          type: string
          title: Pattern
        description:
          anyOf:
            - type: string
            - type: 'null'
          title: Description
        output_value:
          anyOf:
            - type: string
            - type: 'null'
          title: Output Value
        confidence:
          anyOf:
            - type: number
            - type: 'null'
          title: Confidence
        validator:
          anyOf:
            - type: string
            - type: 'null'
          title: Validator
        active:
          anyOf:
            - type: boolean
            - type: 'null'
          title: Active
          default: true
        context_items:
          anyOf:
            - items:
                type: string
              type: array
            - type: 'null'
          title: Context Items
        required_context_matches:
          anyOf:
            - type: integer
            - type: 'null'
          title: Required Context Matches
          default: 0
      type: object
      required:
        - pattern
      title: RegexPattern
      description: Model for regex pattern configuration in tags.
    RuleBasedRule-Input:
      properties:
        tag_value:
          anyOf:
            - type: string
            - type: number
            - type: integer
            - type: 'null'
          title: Tag Value
        condition:
          anyOf:
            - $ref: '#/components/schemas/RuleCondition-Input'
            - type: 'null'
        description:
          anyOf:
            - type: string
            - type: 'null'
          title: Description
        confidence:
          anyOf:
            - type: number
            - type: 'null'
          title: Confidence
      type: object
      title: RuleBasedRule
      description: Model for rule-based tag configuration.
    GovernanceMetadata:
      properties:
        record_code:
          type: string
          title: Record Code
          description: Unique identifier from the retention schedule (e.g., FIN-001)
        retention_period:
          type: string
          title: Retention Period
          description: How long to retain (e.g., '7 years', 'Permanent')
        retention_trigger:
          type: string
          title: Retention Trigger
          description: Event that starts the retention clock (e.g., 'Date of payment')
        disposition:
          type: string
          title: Disposition
          description: Action after retention expires (e.g., 'Destroy', 'Archive')
        ingestion_id:
          type: string
          title: Ingestion Id
          description: UUID grouping all tags from the same CSV upload
      type: object
      required:
        - record_code
        - retention_period
        - retention_trigger
        - disposition
        - ingestion_id
      title: GovernanceMetadata
      description: >-
        Structured metadata for retention/policy governance tags.


        Populated when a tag is ingested from a retention schedule (CSV or
        Collibra Standards).

        Stored as JSONB in the tagschemas table.
    TagPermissions:
      properties:
        can_register:
          type: boolean
          title: Can Register
          default: false
        can_edit:
          type: boolean
          title: Can Edit
          default: false
        can_edit_name:
          type: boolean
          title: Can Edit Name
          default: false
        can_delete:
          type: boolean
          title: Can Delete
          default: false
        can_be_shared:
          type: boolean
          title: Can Be Shared
          default: false
        can_classify:
          type: boolean
          title: Can Classify
          default: false
        locked_by:
          anyOf:
            - type: string
            - type: 'null'
          title: Locked By
      type: object
      title: TagPermissions
      description: >-
        Per-tag, per-caller action permissions (derived at request time).


        ``locked_by`` is the id of a catalog provider that owns the tag's
        external

        binding (a provider with ``locks_registered_tags``, such as Purview);
        when

        set, edit/delete are disallowed. Treat it as an opaque provider id or

        ``null`` — don't special-case a literal value.
    TagUsage:
      properties:
        files_with_tag:
          type: integer
          title: Files With Tag
          default: 0
      type: object
      title: TagUsage
      description: Usage counts for the Tag Library governance view (from tag_usage_stats).
    RuleBasedRule-Output:
      properties:
        tag_value:
          anyOf:
            - type: string
            - type: number
            - type: integer
            - type: 'null'
          title: Tag Value
        condition:
          anyOf:
            - $ref: '#/components/schemas/RuleCondition-Output'
            - type: 'null'
        description:
          anyOf:
            - type: string
            - type: 'null'
          title: Description
        confidence:
          anyOf:
            - type: number
            - type: 'null'
          title: Confidence
      type: object
      title: RuleBasedRule
      description: Model for rule-based tag configuration.
    RuleCondition-Input:
      properties:
        condition:
          anyOf:
            - type: string
              enum:
                - AND
                - OR
            - type: 'null'
          title: Condition
        children:
          anyOf:
            - items:
                $ref: '#/components/schemas/RuleCondition-Input'
              type: array
            - type: 'null'
          title: Children
        tag:
          anyOf:
            - $ref: '#/components/schemas/RuleConditionTag'
            - type: 'null'
      type: object
      title: RuleCondition
      description: >-
        Boolean tree node. Leaf: tag set, children=None. Node: children set,
        tag=None.
    RuleCondition-Output:
      properties:
        condition:
          anyOf:
            - type: string
              enum:
                - AND
                - OR
            - type: 'null'
          title: Condition
        children:
          anyOf:
            - items:
                $ref: '#/components/schemas/RuleCondition-Output'
              type: array
            - type: 'null'
          title: Children
        tag:
          anyOf:
            - $ref: '#/components/schemas/RuleConditionTag'
            - type: 'null'
      type: object
      title: RuleCondition
      description: >-
        Boolean tree node. Leaf: tag set, children=None. Node: children set,
        tag=None.
    RuleConditionTag:
      properties:
        tag_id:
          type: string
          title: Tag Id
        values:
          items:
            anyOf:
              - type: string
              - type: number
              - type: integer
          type: array
          title: Values
          default: []
        operator:
          $ref: '#/components/schemas/RuleOperator'
          default: any
      type: object
      required:
        - tag_id
      title: RuleConditionTag
      description: 'Leaf predicate: a single (tag, operator, values) test.'
    RuleOperator:
      type: string
      enum:
        - any
        - not
        - all
        - ge
        - gt
        - le
        - lt
        - contains
        - not_contains
        - exists
        - not_exists
      title: RuleOperator
  securitySchemes:
    BasicAuth:
      type: http
      scheme: basic
    BearerAuth:
      type: http
      scheme: bearer
    UserIdAuth:
      type: apiKey
      in: header
      name: X-User-ID

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.