Chapter 4. Generate synthetic data


When you customize a model for your enterprise, you must generate high-quality synthetic data to augment your data set, improve model robustness, and cover edge cases.

Red Hat provides the Synthetic Data Generation (SDG) Hub, a modular Python framework for building synthetic data generation pipelines by using composable blocks and flows. Each block performs a specific task, such as LLM chat, parse text, evaluate, or transform data. Flows chain blocks together to create complex data generation pipelines that include validation and parameter management. A flow (data generation pipeline) is a YAML specification that defines an instance of a data generation algorithm.

4.1. Explore the SDG Hub examples

To get started with SDG Hub, explore the provided examples.

Prerequisites

Procedure

  1. To access the SDG Hub examples, clone the SDG Hub Git repository:

  2. Go to the examples directory to view the notebooks and YAML files for the use cases described in the following sections.

Each use case directory includes a README.md file that provides details for each use case, such as instructions, performance notes, and configuration tips.

When you run the example notebooks, consider the following information:

  • Data generation time and statistics: The total time to generate data depends on both the maximum concurrency supported by your endpoint and the complexity of the running flow. Longer flows, such as the flows in the Knowledge Generation notebooks, take more time to complete because they produce a large number of summaries and Q&A pairs, each of which undergoes verification within the pipeline.
  • LLM endpoint requirements: For running flows in the Knowledge Generation notebooks, Red Hat recommends that you set the following values:

    • Set NUMBER_OF_SUMMARIES to a minimum of 10.
    • To achieve reasonable data generation times and avoid timeouts, use an endpoint that supports a maximum concurrency of at least 50.
    • Extend LiteLLM’s request timeout by setting the environment variable LITELLM_REQUEST_TIMEOUT.

4.1.1. SDG Hub Knowledge Tuning example

The knowledge tuning pipeline example shows how to generate synthetic training data from enterprise documents, so that a fine-tuned model can accurately recall domain-specific content and facts in response to user queries.

Pre-trained language models typically encounter most facts only once or twice during training, leaving proprietary or domain-specific knowledge incomplete or absent. The knowledge tuning pipeline example addresses this problem by generating n augmentations per document, where n is a configurable parameter (NUMBER_OF_SUMMARIES), and converting each augmentation into synthetic question and answer (Q&A) pairs. Increasing summary token count leads to superior memorization.

This pipeline example implements the following augmentation instances:

  • Thematic Summaries for capturing high-level ideas.
  • Knowledge Relationships for identifying connections between segments.
  • Atomic Facts for isolating granular details.

For each summary, the system generates three Q&A pairs; it discards excess pairs during post-processing. This architecture is modular. You can integrate additional augmentation types by editing existing flows or by adding new ones.

The output is a high-quality JSONL data set that is ready for consumption through training. This example provides a complete walkthrough of data generation and preparation for training, from document parsing through data set combination.

For benchmark results, token scaling statistics, and custom domain evaluations, see the SDG Hub Knowledge Tuning example repo.

Multilingual knowledge tuning example

The knowledge generation pipeline also includes a multilingual knowledge tuning example that supports creating training data in any language. The example includes pre-built flows for Spanish that are auto-discovered with zero configuration. For other languages, the library automatically translates flows on demand by using an LLM, with a verification pass to ensure accuracy.

To get started, set SDG_LANG (for example, Spanish) and SDG_LANG_CODE (for example, es) in your environment, then run the knowledge generation notebook as normal. The notebook checks for a pre-translated flow variant and uses it if available. If no pre-translated flow exists, the notebook translates all prompt templates, verifies them with a second LLM pass, and registers the new flow for immediate use with no extra code.

Performance benchmarks on the QuALITY benchmark (translated to Spanish) show that multilingual fine-tuning improves domain-specific accuracy while preserving general model capabilities. SFT on Spanish synthetic data improved benchmark accuracy from a 44.47% baseline to 68.88% in RAG settings, while retaining 84-90% of the baseline model’s behavior. For configuration details, benchmark tables, and coverage analysis, see the multilingual documentation.

The text analysis example shows how to generate data for teaching models, to extract meaningful insights from text in structured format. Create custom blocks and extend existing flows for new applications.

4.1.3. SDG Hub RAG Evaluation example

Reliable, repeatable evaluation is essential before you ship RAG or agentic updates to production. The RAG Evaluation example provides a flow for generating data for evaluating RAG systems at scale. The input of the flow is user documents. The output data set is post-processed to work with the RAGAS framework. The flow creates Q&A pairs with ground truth context for evaluating RAG systems. This flow simplifies data generation for RAG workflows.

4.1.4. SDG Hub Red Teaming & AI Safety example

The Teaming & AI Safety example shows how to generate adversarial prompts for testing model safety, guardrails, and robustness against harmful content. It uses a challenger LLM as teacher. This example demonstrates how to create custom safety testing datasets based on your organization’s policies and concerns. The workflow generates harmful prompts with explanations. You can integrate it with security testing tools, such as Garak for automated safety validation on Red Hat OpenShift AI.

4.1.5. SDG Hub Agentic examples

The agentic examples demonstrate training data generation for custom MCP servers and agent tool-calling.

SDG Hub enables the creation of training data for AI agents and tool-calling applications through the following two complementary capabilities: generating tool-use training data from real tool interactions (MCP Server Distillation), and evaluating fine-tuned models through the same agent stack used for data generation (MCP Server Evaluation).

  • MCP Server Distillation - SDG Hub can target any MCP server, and produce structured function-calling conversations ready for supervised fine-tuning. A frontier model actively explores the MCP server’s tools, calling every tool, discovering real data, mapping tool relationships and generating training examples grounded in what it found. The pipeline runs through 4 stages:

    • Expert exploration
    • Question synthesis
    • Quality filtering
    • Expert trajectory generation
  • MCP Server Evaluation - After fine-tuning, to evaluate whether it worked, the evaluation pipeline uses a frontier model to generate gold-standard evaluation tasks at varying complexity levels on any custom MCP server that the input agent has access to. Use cases include training smaller models to use proprietary enterprise APIs and databases, reducing inference costs by replacing expensive frontier models with fine-tuned alternatives, generating expert-quality tool-calling demonstrations at scale, and building domain-specific AI agents for custom tool ecosystems.

Agent Connector Framework

The Agent Connector Framework provides a standardized way to incorporate external tools, agents, APIs, and services into SDG pipelines. Instead of writing custom integration code for each tool, the connector framework offers a pluggable architecture that handles tool-specific communication while SDG Hub orchestrates execution at scale.

The Agent Connector Framework has the following capabilities: * Pluggable connector architecture for any external tool or service * Async orchestration with automated execution at scale * Production-ready error handling and retry logic * Extraction of results from tool interactions to generate rich, behavior-driven training data * Positioning of SDG Hub as a universal orchestration layer for multi-tool workflows, enabling AI engineers to build extensible data generation pipelines that incorporate proprietary tools and third-party services * Existing integrations, such as Langflow and Langgraph

Additional resources

4.2. Performance benchmarks for knowledge tuning

To get an estimate of the total time a flow will take, you can run the dry_run function and set enable_time_estimation to true.

For example, tests that use the gpt-oss-120b LLM on 4x H100 GPUs with the QuALITY dataset (266 articles) showed significant variance between flows.

  • The estimated generation times for the full dataset were approximately 15.12 hours for Extractive Summary and 12.99 hours for Detailed Summary, both of which were evaluated with 50 completions per summary (N=50).
  • In contrast, the Key Facts and Document Based flows, which generated only a single summary per document, completed in approximately 0.35 and 0.44 hours, respectively.
  • Additionally, analysis of the Extractive Summary flow highlights that the steepest time reductions occurred between concurrency levels 10 and 30, with returns observed to diminish significantly beyond 50 in this specific configuration.

To view a graph that illustrates the accuracy on QuALITY Benchmark (4,609 Evaluation QA), go to: https://github.com/Red-Hat-AI-Innovation-Team/sdg_hub/blob/main/examples/knowledge_tuning/enhanced_summary_knowledge_tuning/imgs/quality_benchmark_accuracy.png.

You can generate synthetic data for domain-specific model customization by using a Kubeflow Pipeline (KFP) on Red Hat OpenShift AI, as shown in the following examples.

The Domain Customization Data Generation using Kubeflow Pipelines (KFP) example demonstrates how to generate synthetic data for domain-specific model customization by using Kubeflow Pipelines.

Prerequisites

Procedure

  1. Run the following command to clone the (org-name) AI examples repository that includes the KFP pipeline for knowledge tuning example.

    git clone https://github.com/red-hat-data-services/red-hat-ai-examples
  2. Navigate to the examples/domain_customization_kfp_pipeline directory.
  3. Follow the instructions in the README file to run the example:

    1. Configure an environment variable (.env) file, provide your model endpoint, and store the file as a Kubernetes secret. The KFP pipeline consumes the secret as environment variables.
    2. Generate the KFP pipeline YAML file.
    3. Upload the YAML file to OpenShift AI and deploy the pipeline.

Verification

The example pipeline generates three types of document augmentations and four types of QA on top of 3 augmentation and 1 original document. It stores the generated data in the Cloud Object Storage (COS) bucket that is linked through the pipeline server.

4.3.2. Basic Kubeflow pipeline example

The Kubeflow Pipelines guided example uses a minimal test pipeline to run a simple three-block flow that generates a question from each input document.

You can replace this flow with your own to perform more complex data generation tasks, such as multi-step augmentation, knowledge Q&A generation, or domain-specific transformations.

Prerequisites

  • Access to an OpenShift AI cluster with Kubeflow Pipelines installed.
  • A deployed LLM endpoint compatible with the LiteLLM format, for example: openai/gpt-4o-mini .
  • The kfp Python SDK (version 2.15.2 or later) installed locally for pipeline compilation.

Procedure

  1. Clone the Kubeflow Pipelines Components repository that includes the SDG component and pipeline:

    $ git clone https://github.com/kubeflow/pipelines-components
  2. Navigate to the pipelines/data_processing/sdg directory.
  3. Prepare Kubernetes resources for the pipeline:

    1. Create a ConfigMap containing your SDG flow YAML definition (the flow defines the sequence of data processing and LLM blocks to execute):

      $ oc create configmap sdg-llm-test-flow --from-file=llm_test_flow.yaml
    2. Create a ConfigMap containing any prompt template files referenced by the flow:

      $ oc create configmap sdg-llm-test-prompt --from-file=prompts/
    3. Create a Kubernetes Secret with your LLM API key:

      $ oc create secret generic llm-credentials --from-literal=api_key=<your-api-key>
  4. Compile the KFP pipeline YAML file:

    $ python pipeline.py

    The output of this command is the sdg_llm_pipeline.yaml file.

  5. Upload the compiled sdg_llm_pipeline.yaml file to OpenShift AI and deploy the pipeline. When creating a pipeline run, configure the following parameters:
Expand
ParameterDefaultDescription

model

openai/gpt-4o-mini

LiteLLM model identifier for your LLM endpoint.

max_concurrency

1

Maximum concurrent LLM requests.

temperature

0.7

LLM sampling temperature (0.0-2.0).

max_tokens

256

Maximum response tokens per LLM call.

The example pipeline uses llm_test_flow.yaml, a minimal three-block flow designed to demonstrate the SDG component end-to-end. It takes a JSONL data set with document and domain columns and generates a question for each document:

Expand
BlockTypePurpose

build_question_prompt

PromptBuilderBlock

Reads the document column and builds a chat prompt using a template (prompts/generate_question.yaml) that instructs the LLM to generate a short question about the text.

generate_question

LLMChatBlock

Sends the constructed prompt to the configured LLM and captures the raw response.

extract_question

LLMResponseExtractorBlock

Extracts the question text from the LLM response into a clean output column.

The prompt template uses a system message ("You are a helpful assistant that generates a short question about the given text") and a user message that inserts the {{document}} content.

Verification

The example pipeline executes two stages:

  1. Create sample data - Generates a small JSONL data set with three rows containing document and domain columns.
  2. Run SDG flow - Executes the three-block flow above against the sample data using the configured LLM endpoint.

When complete, the pipeline produces a KFP data set artifact containing the generated synthetic data in JSONL format (original columns plus the generated question columns), along with execution metrics (input rows, output rows, and execution time). If the pipeline server is linked to Cloud Object Storage, the artifacts are persisted there.

You can customize the basic Kubeflow pipeline example:

Use a different flow
Replace the flow YAML with your own. A flow is a YAML file that defines a sequence of blocks to execute on your data. You can chain together any combination of blocks supported by SDG Hub.
Use a built-in flow from the SDG Hub registry

Instead of mounting a custom flow YAML, you can reference a built-in flow by its registry ID. In the pipeline.py file, replace flow_yaml_path with flow_id:

sdg_task = sdg(
    input_artifact=data_task.outputs["output_data"],
    flow_id="your-builtin-flow-id",
    model=model,
    max_concurrency=max_concurrency,
    temperature=temperature,
    max_tokens=max_tokens,
)

When using a built-in flow, you do not need the flow ConfigMap.

Bring your own input data

The example pipeline generates sample data inline. To use your own data:

From a PVC: Mount a PersistentVolumeClaim and pass the path via the input_pvc_path parameter instead of input_artifact.

From an upstream component: Connect any KFP component that outputs a dsl.data set artifact in JSONL format to the input_artifact input of the SDG component.

Your input data must include the columns required by your chosen flow. These columns are defined in the flow’s data set_requirements.required_columns.

Override parameters at runtime

Use runtime_params to override individual block parameters without modifying the flow YAML:

sdg_task = sdg(
    ...,
    runtime_params={"generate_question": {"temperature": 0.9, "max_tokens": 512}},
)
Enable checkpointing for large data sets

For long-running flows, enable checkpointing to allow resuming from the last saved state:

sdg_task = sdg(
    ...,
    checkpoint_pvc_path="/mnt/checkpoints/my-run",
    save_freq=50,
)
Export output to a PVC

In addition to the KFP artifact, you can export the generated data to a mounted PVC for direct access:

sdg_task = sdg(
    ...,
    export_to_pvc=True,
    export_path="/mnt/output",
)

The output is saved to <export_path>/<flow_name>/<timestamp>/generated.jsonl.

Additional resources

Red Hat logoGithubredditYoutubeTwitter

Learn

Try, buy, & sell

Communities

About Red Hat

We deliver hardened solutions that make it easier for enterprises to work across platforms and environments, from the core datacenter to the network edge.

Making open source more inclusive

Red Hat is committed to replacing problematic language in our code, documentation, and web properties. For more details, see the Red Hat Blog.

About Red Hat Documentation

Legal Notice

Theme

© 2026 Red Hat
Back to top