Structured Outputs, Jinja Expressions, and Conditional Generation
🎨 Data Designer Tutorial: Structured Outputs, Jinja Expressions, and Conditional Generation
📚 What you'll learn
In this notebook, we will continue our exploration of Data Designer, demonstrating more advanced data generation using structured outputs, Jinja expressions, and conditional generation with skip.when.
If this is your first time using Data Designer, we recommend starting with the first notebook in this tutorial series.
📦 Import Data Designer
-
data_designer.configprovides access to the configuration API. -
DataDesigneris the main interface for data generation.
⚙️ Initialize the Data Designer interface
-
DataDesigneris the main object that is used to interface with the library. -
When initialized without arguments, the default model providers are used.
🎛️ Define model configurations
-
Each
ModelConfigdefines a model that can be used during the generation process. -
The "model alias" is used to reference the model in the Data Designer config (as we will see below).
-
The "model provider" is the external service that hosts the model (see the model config docs for more details).
-
By default, we use build.nvidia.com as the model provider.
🏗️ Initialize the Data Designer Config Builder
-
The Data Designer config defines the dataset schema and generation process.
-
The config builder provides an intuitive interface for building this configuration.
-
The list of model configs is provided to the builder at initialization.
🧑🎨 Designing our data
-
We will again create a product review dataset, but this time we will use structured outputs and Jinja expressions.
-
Structured outputs let you specify the exact schema of the data you want to generate.
-
Data Designer supports schemas specified using either json schema or Pydantic data models (recommended).
We'll define our structured outputs using Pydantic data models
💡 Why Pydantic?
Pydantic models provide better IDE support and type validation.
They are more Pythonic than raw JSON schemas.
They integrate seamlessly with Data Designer's structured output system.
Next, let's design our product review dataset using a few more tricks compared to the previous notebook.
Next, we will use more advanced Jinja expressions to create new columns.
Jinja expressions let you:
-
Access nested attributes:
{{ customer.first_name }} -
Combine values:
{{ customer.first_name }} {{ customer.last_name }} -
Use conditional logic:
{% if condition %}...{% endif %}
🚦 Conditional generation with skip.when
So far, every column is generated for every row. But sometimes an expensive LLM column only makes sense for a subset of rows — for example, a detailed complaint analysis is only useful when the review is negative.
Data Designer lets you skip column generation on a per-row basis using SkipConfig.
Skipped rows receive None by default, but you can provide a sentinel value with
skip=dd.SkipConfig(when="...", value="N/A") to write a specific value instead.
There are three patterns to know:
| Pattern | How | Effect |
|---|---|---|
| Expression gate | skip=dd.SkipConfig(when="...") |
Skip this column when the Jinja2 expression is truthy |
| Skip propagation (default) | Downstream column depends on a skipped column | Automatically skipped too (propagate_skip=True by default) |
| Propagation opt-out | propagate_skip=False on the downstream column |
Always generates, even if an upstream was skipped |
Pattern 1 — Expression gate. Only generate a detailed complaint analysis when the customer gave a low rating (1 or 2 stars).
Rows where the rating is 3 or higher will get None for this column.
Pattern 2 — Skip propagation. action_items depends on complaint_analysis.
When complaint_analysis is skipped, action_items auto-skips too because
propagate_skip defaults to True.
Pattern 3 — Propagation opt-out. review_summary also depends on complaint_analysis,
but sets propagate_skip=False so it always generates. The prompt uses a Jinja conditional
to handle the case where complaint_analysis is None.
🔁 Iteration is key – preview the dataset!
-
Use the
previewmethod to generate a sample of records quickly. -
Inspect the results for quality and format issues.
-
Adjust column configurations, prompts, or parameters as needed.
-
Re-run the preview until satisfied.
📊 Analyze the generated data
-
Data Designer automatically generates a basic statistical analysis of the generated data.
-
This analysis is available via the
analysisproperty of generation result objects.
🆙 Scale up!
-
Happy with your preview data?
-
Use the
createmethod to submit larger Data Designer generation jobs.
⏭️ Next Steps
Check out the following notebook to learn more about: