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

# Generate schema

> Use AI to generate a schema from sample data.

## Request body

<ParamField body="sample_data" type="string" required>
  A sample of the data you want to extract. Can be raw text, CSV rows, or any structured format. The AI analyzes this to determine appropriate columns and types. Truncated to 5,000 characters.
</ParamField>

<ParamField body="name" type="string">
  A name for the generated schema. If omitted, the AI generates one based on the data.
</ParamField>

## Response

Returns the newly created schema object with AI-generated column definitions (same shape as [Get schema](/api-reference/schemas/get)).

<RequestExample>
  ```typescript TypeScript theme={null}
  const schema = await client.schemas.generate({
    sample_data: "Product: iPhone 15 Pro, Price: $999, Storage: 128GB...",
    name: "Smartphones",
  });

  console.log(schema.name);    // "Smartphones"
  console.log(schema.columns); // AI-generated columns
  ```

  ```python Python theme={null}
  schema = client.schemas.generate(
      sample_data="Product: iPhone 15 Pro, Price: $999, Storage: 128GB...",
      name="Smartphones",
  )

  print(schema["name"])     # "Smartphones"
  print(schema["columns"])  # AI-generated columns
  ```

  ```bash cURL theme={null}
  curl -X POST "https://hub.banditshq.com/api/v1/schemas/generate" \
    -H "Authorization: Bearer lasso_..." \
    -H "Content-Type: application/json" \
    -d '{
      "sample_data": "Product: iPhone 15 Pro, Price: $999, Storage: 128GB, Color: Natural Titanium, Weight: 187g\nProduct: Galaxy S24 Ultra, Price: $1299, Storage: 256GB, Color: Titanium Gray, Weight: 232g",
      "name": "Smartphones"
    }'
  ```
</RequestExample>

<ResponseExample>
  ```json Response theme={null}
  {
    "id": "schema_gen123",
    "name": "Smartphones",
    "description": null,
    "is_default": false,
    "columns": [
      { "key": "product_name", "label": "Product Name", "type": "text", "required": true },
      { "key": "price", "label": "Price", "type": "number" },
      { "key": "storage", "label": "Storage", "type": "text" },
      { "key": "color", "label": "Color", "type": "text" }
    ],
    "created_at": "2025-03-01T10:00:00.000Z",
    "updated_at": "2025-03-01T10:00:00.000Z"
  }
  ```
</ResponseExample>

<Tip>
  The AI infers column types automatically. For example, it detects price fields as `number`, URLs as `url`, and lists of values as `tags` or `enum`.
</Tip>
