---
title: Dataset Factory
seo:
  title: Dataset Factory — Python SDK
  description: >-
    Reference for DatasetSchemaProperty, DatasetSchema, DatasetFactory,
    validate_dataset_schema, and infer_schema_from_examples. (Python SDK)
description: >-
  Reference for DatasetSchemaProperty, DatasetSchema, DatasetFactory,
  validate_dataset_schema, and infer_schema_from_examples.
---

| Prop | Type | Default | Description |
| - | - | - | - |
| `DatasetColumnType?` | `Any` | `Literal['string', 'integer', 'number', 'boolean', 'array', 'object', 'trace']` | |

**Classes**

**[DatasetSchemaProperty](/sdk-reference/python/datasets/dataset_factory/DatasetSchemaProperty)**

**[DatasetSchema](/sdk-reference/python/datasets/dataset_factory/DatasetSchema)**

**[DatasetFactory](/sdk-reference/python/datasets/dataset_factory/DatasetFactory)**

**Functions**

## validate\_dataset\_schema()

Validate a dataset JSON Schema client-side before sending.

Mirrors the server's structural checks so obvious mistakes fail fast
without a round-trip; the server remains the source of truth for full
JSON Schema validation.

**ValueError**: If the schema is not a dict, does not declare top-level
`type: "object"`, lacks a `properties` object, or declares
more than one trace-typed column.

```python
def validate_dataset_schema(schema) -> None:
```

### Parameters

| Prop | Type | Default | Description |
| - | - | - | - |
| `schema` | `Mapping[str, Any]` | - | |

### Returns

`None`

***

## \_json\_schema\_type()

```python
def _json_schema_type(value) -> str:
```

### Parameters

| Prop | Type | Default | Description |
| - | - | - | - |
| `value` | `Any` | - | |

### Returns

`str`

***

## infer\_schema\_from\_examples()

Infer a JSON Schema from a set of examples.

Convenience for `client.datasets.create()` when no explicit schema is
supplied. Property types are inferred from the example values; every
example must contain every declared field, so examples must share one
shape (the same set of non-None fields). Heterogeneous examples (where
some examples are missing fields that others have) are rejected with a
`ValueError`. Inferred types are JSON Schema primitives only; to
declare a trace column (`{"type": "trace"}`) pass an explicit schema.

**ValueError**: If no examples are provided or examples have
heterogeneous fields.

```python
def infer_schema_from_examples(examples) -> typing.Dict:
```

### Parameters

| Prop | Type | Default | Description |
| - | - | - | - |
| `examples` | `Sequence[Example]` | - | Examples to infer the schema from. Must be non-empty and homogeneous (all examples share the same set of property keys). |

### Returns

`typing.Dict` - A JSON Schema dict of the form
`{"type": "object", "properties": {...}}` declaring the example
fields.
