---
title: "Infer Schema From File"
method: POST
path: "/public/infer-schema"
tags: ["Enrich"]
---

# Infer Schema From File

`POST /public/infer-schema`

## Request

- Base URL: `https://catalogapi.rastro.ai/api`
- URL: `https://catalogapi.rastro.ai/api/public/infer-schema`
- Auth: HTTP bearer

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)

## Headers

- `X-Organization-Id` string, nullable

## Request body `multipart/form-data`

- BodyInferSchemaFromFileApiPublicInferSchemaPost
  - `file` string, binary, required: CSV or Excel file to analyze
  - `prompt` string, required: Description of the data (e.g., 'Product catalog for electronics retailer')
  - `generate_taxonomy` boolean: If true, also generate a suggested taxonomy
  - `max_sample_rows` integer: Maximum rows to sample for analysis (default 20)

## Response `200`

Successful Response

- InferSchemaResponse: Response with inferred configuration for enrichment.
  - `file_name` string, required: Name of the uploaded file
  - `total_rows` integer, required: Total rows in the file
  - `sample_rows_used` integer, required: Number of rows sampled for inference
  - `suggested_schema` object, required: 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` FieldDefinition[], required: Fields to extract via web enrichment. Use as output_schema in /public/enrich.
    - `name` string, required: Field name
    - `type` string: Field type: string, number, integer, boolean, array
    - `description` string, required: Description of what to extract for this field
    - `array_element_type` string, nullable: For array fields, the type of elements: string, number, integer, image_url
    - `unit` string, nullable: Units for numeric fields (e.g., 'kg', 'USD', 'cm')
    - `enum` string[], nullable: Constrain extraction to these specific values
    - `items_enum` string[], nullable: For array fields, constrain items to these specific values
    - `sample_values` string[], nullable: Example values to guide extraction
    - `required` boolean, nullable: Whether the field is required
    - `merge` boolean, nullable: Whether to merge with existing values
    - `pattern` string, nullable: Optional regex pattern constraint for extracted text
    - `pattern_message` string, nullable: Human-readable guidance for the pattern constraint
    - `min_length` integer, nullable: Minimum string length
    - `max_length` integer, nullable: Maximum string length
    - `minimum` number, nullable: Minimum numeric value
    - `maximum` number, nullable: Maximum numeric value
    - `unique` boolean, nullable: Whether the field should be unique within the target catalog
    - `semantic_type` string, nullable: Optional semantic type hint such as image_url or document_url
  - `suggested_taxonomy` object, nullable: Taxonomy in TaxonomyInput format. Only present if generate_taxonomy=true.

## Other responses

- `422`: Validation Error

---

[API](https://skmtc.dev/rastro-ai/apis/rastro-public-api.md) - [All operations](https://skmtc.dev/rastro-ai/apis/rastro-public-api/llms.txt) - [OpenAPI document](https://skmtc.dev/rastro-ai/apis/rastro-public-api/revisions/57c8ed4854bb?raw)
