Skip to content

Commit a426efc

Browse files
authored
docs(dataset-generation): document output_schema configuration (#668)
Update the dataset generation configuration documentation to detail the new `output_schema` setting under `generation` and the `custom` format option under `output`. - Add schema table entries for `generation.output_schema` and `output.format` - Include a section explaining custom structured output with code examples - List current limitations regarding field validation, CLI flags, and provider support Signed-off-by: Luke Hinds <lukehinds@gmail.com>
1 parent 654963d commit a426efc

2 files changed

Lines changed: 86 additions & 0 deletions

File tree

docs/dataset-generation/configuration.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,42 @@ Controls sample generation.
145145
| `max_retries` | int | 3 | Retries on API failures |
146146
| `sample_retries` | int | 2 | Retries on validation failures |
147147
| `max_tokens` | int | 2000 | Max tokens per generation |
148+
| `output_schema` | object | - | Custom JSON Schema for structured output (see below) |
148149
| `llm` | object | - | Override shared LLM settings |
149150

151+
#### generation.output_schema (Custom Structured Output)
152+
153+
By default, DeepFabric generates samples in a conversation format (`basic` or `cot`, made up of messages). Setting `output_schema` bypasses the conversation format entirely: DeepFabric generates directly into your JSON Schema via constrained decoding, and each output record matches that schema instead of the OpenAI messages format.
154+
155+
```yaml title="Example: Custom schema output"
156+
generation:
157+
system_prompt: "Extract structured product information from the topic."
158+
instructions: "Populate every field with realistic, specific values."
159+
output_schema:
160+
type: object
161+
properties:
162+
product_name: {type: string}
163+
category: {type: string}
164+
price_usd: {type: number}
165+
in_stock: {type: boolean}
166+
required: [product_name, category, price_usd, in_stock]
167+
168+
output:
169+
format: custom # documents intent; the switch is driven by output_schema
170+
num_samples: 100
171+
batch_size: 5
172+
save_as: "products.jsonl"
173+
```
174+
175+
Set `output.format: custom` alongside it to document the intent in your config — see the `output` section below for how `format` is used.
176+
177+
!!! warning "Limitations"
178+
- **No field-level validation.** DeepFabric confirms the model's response is valid JSON but does not check it against `required`, types, `enum`, or nested `properties` in your schema. Malformed or incomplete-but-valid JSON will pass through into the dataset.
179+
- **No example demonstrations.** Unlike the standard conversation prompts, the custom-schema prompt does not support `generation.example_data`; example demonstrations have no effect in this mode.
180+
- **Constrained decoding depends on the provider.** OpenAI, OpenRouter, Ollama, and local providers enforce the schema via [Outlines](https://github.com/dottxt-ai/outlines); Gemini and Anthropic use their native structured-output APIs. Enforcement quality varies by provider and model.
181+
- **No CLI override.** `output_schema` can only be set via YAML config or the Python API (`DataSetGenerator(output_schema={...}, ...)`); there is no `--output-schema` flag.
182+
- **Retries follow the same validation-error heuristics** as normal generation (`sample_retries`). If a schema-related error isn't recognized as a validation error, it fails immediately instead of retrying.
183+
150184
#### generation.conversation
151185

152186
| Field | Type | Options | Description |
@@ -199,6 +233,7 @@ Controls final dataset.
199233
| `num_samples` | int \| string | required | Total samples: integer, `"auto"`, or percentage like `"50%"` |
200234
| `batch_size` | int | 1 | Parallel generation concurrency (number of simultaneous LLM calls) |
201235
| `save_as` | string | required | Output file path |
236+
| `format` | string | "messages" | `messages` (OpenAI chat format) or `custom` (matches `generation.output_schema`) |
202237
| `checkpoint` | object | - | Checkpoint configuration (see below) |
203238

204239
!!! tip "Auto and Percentage Samples"

examples/custom-schema.yaml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#####################################################################
2+
# Custom Structured Output Configuration
3+
#####################################################################
4+
# Demonstrates generation.output_schema: instead of the default
5+
# conversation (messages) format, each sample is generated directly
6+
# into a user-defined JSON Schema via constrained decoding.
7+
#####################################################################
8+
9+
# Topic generation - creates a graph of related topics
10+
topics:
11+
prompt: "Consumer electronics products"
12+
mode: graph
13+
prompt_style: anchored
14+
depth: 2
15+
degree: 4
16+
save_as: "custom-schema-topics.jsonl"
17+
18+
llm:
19+
provider: "openai"
20+
model: "gpt-4o"
21+
temperature: 0.8
22+
23+
# Data generation - generates directly into output_schema, bypassing
24+
# the conversation/messages format entirely.
25+
generation:
26+
system_prompt: "Extract structured product information for the given topic."
27+
instructions: "Populate every field with realistic, specific values."
28+
29+
output_schema:
30+
type: object
31+
properties:
32+
product_name: {type: string}
33+
category: {type: string}
34+
price_usd: {type: number}
35+
in_stock: {type: boolean}
36+
required: [product_name, category, price_usd, in_stock]
37+
38+
max_retries: 3
39+
sample_retries: 2
40+
41+
llm:
42+
provider: "openai"
43+
model: "gpt-4o"
44+
temperature: 0.5
45+
46+
# Output configuration
47+
output:
48+
format: custom # records match generation.output_schema, not messages
49+
num_samples: 10
50+
batch_size: 3
51+
save_as: "custom-schema-dataset.jsonl"

0 commit comments

Comments
 (0)