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

# Infer Schema From File

> Analyze an uploaded file and infer enrichment configuration.

Upload a CSV or Excel file, and get back:
- **suggested_schema**: JSON Schema with all fields (existing + suggested enrichments)
- **web_enrichment_fields**: Fields to use with /public/enrich endpoint
- **suggested_taxonomy**: Category hierarchy (if generate_taxonomy=true)

This endpoint helps you configure an enrichment pipeline without manual schema definition.

**Example usage:**
1. Upload your data file with a description
2. Use the returned `web_enrichment_fields` as `output_schema` in `/public/enrich`
3. Use `suggested_taxonomy` with `predict_taxonomy=true` in `/public/enrich`

**Supported file formats:**
- CSV (.csv)
- Excel (.xlsx, .xls)



## OpenAPI

````yaml /api-reference/openapi.json post /public/infer-schema
openapi: 3.1.0
info:
  title: Rastro Public API
  description: >-
    Public API for enrichment, catalog management, workflows, activities,
    snapshots, taxonomy, and MCP integrations.
  version: 0.1.0
servers:
  - url: https://catalogapi.rastro.ai/api
security:
  - bearerAuth: []
paths:
  /public/infer-schema:
    post:
      tags:
        - Enrich
      summary: Infer Schema From File
      description: >-
        Analyze an uploaded file and infer enrichment configuration.


        Upload a CSV or Excel file, and get back:

        - **suggested_schema**: JSON Schema with all fields (existing +
        suggested enrichments)

        - **web_enrichment_fields**: Fields to use with /public/enrich endpoint

        - **suggested_taxonomy**: Category hierarchy (if generate_taxonomy=true)


        This endpoint helps you configure an enrichment pipeline without manual
        schema definition.


        **Example usage:**

        1. Upload your data file with a description

        2. Use the returned `web_enrichment_fields` as `output_schema` in
        `/public/enrich`

        3. Use `suggested_taxonomy` with `predict_taxonomy=true` in
        `/public/enrich`


        **Supported file formats:**

        - CSV (.csv)

        - Excel (.xlsx, .xls)
      operationId: infer_schema_from_file_api_public_infer_schema_post
      parameters:
        - name: X-Organization-Id
          in: header
          required: false
          schema:
            anyOf:
              - type: string
              - type: 'null'
            title: X-Organization-Id
      requestBody:
        required: true
        content:
          multipart/form-data:
            schema:
              $ref: >-
                #/components/schemas/Body_infer_schema_from_file_api_public_infer_schema_post
      responses:
        '200':
          description: Successful Response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/InferSchemaResponse'
        '422':
          description: Validation Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HTTPValidationError'
      security:
        - bearerAuth: []
components:
  schemas:
    Body_infer_schema_from_file_api_public_infer_schema_post:
      properties:
        file:
          type: string
          format: binary
          title: File
          description: CSV or Excel file to analyze
        prompt:
          type: string
          title: Prompt
          description: >-
            Description of the data (e.g., 'Product catalog for electronics
            retailer')
        generate_taxonomy:
          type: boolean
          title: Generate Taxonomy
          description: If true, also generate a suggested taxonomy
          default: false
        max_sample_rows:
          type: integer
          title: Max Sample Rows
          description: Maximum rows to sample for analysis (default 20)
          default: 20
      type: object
      required:
        - file
        - prompt
      title: Body_infer_schema_from_file_api_public_infer_schema_post
    InferSchemaResponse:
      properties:
        file_name:
          type: string
          title: File Name
          description: Name of the uploaded file
        total_rows:
          type: integer
          title: Total Rows
          description: Total rows in the file
        sample_rows_used:
          type: integer
          title: Sample Rows Used
          description: Number of rows sampled for inference
        suggested_schema:
          additionalProperties: true
          type: object
          title: Suggested Schema
          description: >-
            JSON Schema with all fields found in the data. 'x-field-category'
            indicates 'input' (existing) or 'enriched' (suggested to add via
            web).
        web_enrichment_fields:
          items:
            $ref: '#/components/schemas/FieldDefinition'
          type: array
          title: Web Enrichment Fields
          description: >-
            Fields to extract via web enrichment. Use as output_schema in
            /public/enrich.
        suggested_taxonomy:
          anyOf:
            - additionalProperties: true
              type: object
            - type: 'null'
          title: Suggested Taxonomy
          description: >-
            Taxonomy in TaxonomyInput format. Only present if
            generate_taxonomy=true.
      type: object
      required:
        - file_name
        - total_rows
        - sample_rows_used
        - suggested_schema
        - web_enrichment_fields
      title: InferSchemaResponse
      description: Response with inferred configuration for enrichment.
    HTTPValidationError:
      properties:
        detail:
          items:
            $ref: '#/components/schemas/ValidationError'
          type: array
          title: Detail
      type: object
      title: HTTPValidationError
    FieldDefinition:
      description: >-
        Definition for a single field to extract - matches attribute mapper
        field schema.
      properties:
        name:
          description: Field name
          title: Name
          type: string
        type:
          default: string
          description: 'Field type: string, number, integer, boolean, array'
          title: Type
          type: string
        description:
          description: Description of what to extract for this field
          title: Description
          type: string
        array_element_type:
          anyOf:
            - type: string
            - type: 'null'
          default: null
          description: >-
            For array fields, the type of elements: string, number, integer,
            image_url
          title: Array Element Type
        unit:
          anyOf:
            - type: string
            - type: 'null'
          default: null
          description: Units for numeric fields (e.g., 'kg', 'USD', 'cm')
          title: Unit
        enum:
          anyOf:
            - items:
                type: string
              type: array
            - type: 'null'
          default: null
          description: Constrain extraction to these specific values
          title: Enum
        items_enum:
          anyOf:
            - items:
                type: string
              type: array
            - type: 'null'
          default: null
          description: For array fields, constrain items to these specific values
          title: Items Enum
        sample_values:
          anyOf:
            - items:
                type: string
              type: array
            - type: 'null'
          default: null
          description: Example values to guide extraction
          title: Sample Values
        required:
          anyOf:
            - type: boolean
            - type: 'null'
          default: null
          description: Whether the field is required
          title: Required
        merge:
          anyOf:
            - type: boolean
            - type: 'null'
          default: null
          description: Whether to merge with existing values
          title: Merge
        pattern:
          anyOf:
            - type: string
            - type: 'null'
          default: null
          description: Optional regex pattern constraint for extracted text
          title: Pattern
        pattern_message:
          anyOf:
            - type: string
            - type: 'null'
          default: null
          description: Human-readable guidance for the pattern constraint
          title: Pattern Message
        min_length:
          anyOf:
            - type: integer
            - type: 'null'
          default: null
          description: Minimum string length
          title: Min Length
        max_length:
          anyOf:
            - type: integer
            - type: 'null'
          default: null
          description: Maximum string length
          title: Max Length
        minimum:
          anyOf:
            - type: number
            - type: 'null'
          default: null
          description: Minimum numeric value
          title: Minimum
        maximum:
          anyOf:
            - type: number
            - type: 'null'
          default: null
          description: Maximum numeric value
          title: Maximum
        unique:
          anyOf:
            - type: boolean
            - type: 'null'
          default: null
          description: Whether the field should be unique within the target catalog
          title: Unique
        semantic_type:
          anyOf:
            - type: string
            - type: 'null'
          default: null
          description: Optional semantic type hint such as image_url or document_url
          title: Semantic Type
      required:
        - name
        - description
      title: FieldDefinition
      type: object
    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:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: Rastro API key or user token

````