DeepFabric generates synthetic training data for language models. By combining reasoning traces with tool-calling patterns, it creates high-quality, domain-specific datasets that teach models to think, plan, and act effectively, call tools correctly, and conform to strict schema structures.
What sets DeepFabric apart from other dataset generation tools is its ability to ensure high diversity yet domain-anchored relevance through unique topic graph generation algorithms. This guides sample creation to cover all necessary subtopics while avoiding redundancy, which is where other tools often fall short, resulting in model overfit.
Constrained decoding and response validation ensure that generated samples strictly adhere to desired formats, ensuring datasets have exact syntax and structure for use in model training pipelines.
Once your dataset is generated, it can be automatically uploaded to Hugging Face for easy sharing and versioning, and directly imported into popular training frameworks like TRL, Unsloth, and Axolotl. Post-training, DeepFabric's built-in evaluation engine assesses model performance, whereby models prove their capabilities on unseen tasks derived from training splits—covering evaluation-only questions, answers, and tool traces.
Quickstart
DeepFabric can be used in several ways, as a library, CLI tool, or via YAML configuration. Here's a quick example using the CLI:
pip install deepfabric
export OPENAI_API_KEY="your-api-key"
deepfabric generate \
--topic-prompt "Python programming fundamentals" \
--generation-system-prompt "You are a Python expert" \
--mode tree \
--depth 3 \
--degree 3 \
--num-samples 9 \
--batch-size 3 \
--provider openai \
--model gpt-4o \
--output-save-as dataset.jsonl
This generates a topic tree and creates 27 unique leaf topics, then generates 27 training samples saved to dataset.jsonl, giving you 100% topic coverage.
Configuration
DeepFabric also uses YAML configuration with three main sections and optional shared LLM defaults:
# Optional: Shared LLM defaults (inherited by topics and generation)
llm:
provider: "openai"
model: "gpt-4o"
temperature: 0.7
# TOPICS: Generate the topic tree/graph
topics:
prompt: "Building production-ready REST APIs with Python"
mode: tree # tree | graph
depth: 3
degree: 3
save_as: "topics.jsonl"
# Optional: Override shared LLM settings
llm:
model: "gpt-4o-mini" # Use cheaper model for topics
# GENERATION: Create training samples from topics
generation:
system_prompt: |
You are an expert Python backend developer and technical educator.
Create practical, production-ready code examples with clear explanations.
Include error handling, type hints, and follow PEP 8 conventions.
# Additional instructions for sample generation
instructions: |
Focus on real-world scenarios developers encounter daily.
Include both happy path and edge case handling.
Provide context on when and why to use specific patterns.
conversation:
type: chain_of_thought # basic | chain_of_thought
reasoning_style: agent # freetext | agent (for chain_of_thought)
agent_mode: single_turn # single_turn | multi_turn (for agent)
# Tool configuration (required for agent modes)
tools:
registry_path: "dev-tools.yaml" # Path to tool definitions
# available: [] # Specific tools to use (empty = all)
# custom: [] # Inline tool definitions
max_per_query: 3 # Maximum tools per query
strict: true # Discard samples exceeding max (vs truncate)
max_retries: 3 # Retries for failed generations
sample_retries: 2 # Retries for validation failures
max_tokens: 2000 # Max tokens per generation
# Optional: Override shared LLM settings
llm:
temperature: 0.3 # Lower temp for consistent code
# OUTPUT: Final dataset configuration
output:
# System prompt that goes INTO the training data
# This is what the trained model will see as its system message
system_prompt: |
You are a helpful Python programming assistant specialized in REST API
development. You provide clear, production-ready code with explanations.
Always consider security, error handling, and best practices.
include_system_message: true # Whether to include system message in output
num_samples: 4 # Total training samples to generate
batch_size: 3 # Parallel generation batch size
save_as: "api-dataset.jsonl"
# Optional: Upload to Hugging Face
huggingface:
repository: "your-username/api-dataset-training-name"
tags: ["python", "programming"]
Within dev-tools.yaml, define tools the model can use during generation, for example:
- name: get_commit
description: "Get details for a commit from a GitHub repository"
parameters:
- name: owner
type: str
description: "Repository owner"
required: true
- name: repo
type: str
description: "Repository name"
required: true
- name: sha
type: str
description: "Commit SHA, branch name, or tag name"
required: true
- name: include_diff
type: bool
description: "Whether to include file diffs and stats"
required: false
returns: "Commit details including author, message, and changed files"
- name: "search_file"
description: "Search for a keyword in a text file"
parameters:
- name: file_path
type: str
description: "Path to the text file"
required: true
- name: keyword
type: str
description: "Keyword to search for"
Run with:
deepfabric generate config.yaml
Generate, Train, Evaluate
DeepFabric returns standard HuggingFace datasets, making it easy to integrate with any training framework.
1. Generate Dataset
deepfabric generate config.yaml --output-save-as dataset.jsonl
Or upload to HuggingFace Hub:
deepfabric upload dataset.jsonl --repo your-username/my-dataset
2. Load and Split for Training
from datasets import load_dataset
from transformers import AutoTokenizer
# Load from Hub
dataset = load_dataset("alwaysfurther/deepfabric-generic-tools", split="train")
# Split into train/eval
splits = dataset.train_test_split(test_size=0.1, seed=42)
train_ds = splits["train"]
eval_ds = splits["test"]
# Format using your tokenizer
tokenizer = AutoTokenizer.from_pretrained("Qwen/Qwen2.5-7B-Instruct")
def format_example(example):
messages = [{k: v for k, v in msg.items() if v is not None}
for msg in example["messages"]]
return {"text": tokenizer.apply_chat_template(messages, tokenize=False)}
formatted_train = train_ds.map(format_example)
3. Train with TRL or Unsloth
from trl import SFTTrainer, SFTConfig
trainer = SFTTrainer(
model=model,
tokenizer=tokenizer,
train_dataset=formatted_train,
args=SFTConfig(output_dir="./output", num_train_epochs=3),
)
trainer.train()
4. Evaluate Your Model
from deepfabric.evaluation import Evaluator, EvaluatorConfig, InferenceConfig
config = EvaluatorConfig(
inference_config=InferenceConfig(
model_path="./output/checkpoint-final", # Local path or HF Hub ID
backend="transformers",
),
)
evaluator = Evaluator(config)
results = evaluator.evaluate(dataset=eval_ds) # Pass HF Dataset directly
print(f"Tool Selection Accuracy: {results.metrics.tool_selection_accuracy:.2%}")
print(f"Parameter Accuracy: {results.metrics.parameter_accuracy:.2%}")
print(f"Overall Score: {results.metrics.overall_score:.2%}")
Providers
| Provider | Local/Cloud | Best For |
|---|---|---|
| OpenAI | Cloud | High quality, complex tasks |
| Anthropic | Cloud | Nuanced reasoning |
| Google Gemini | Cloud | Cost-effective at scale |
| Ollama | Local | Privacy, unlimited generation |
| OpenRouter | Cloud | Flexible model choice |
Resources
Development
git clone https://github.com/always-further/deepfabric
cd deepfabric
uv sync --all-extras
make test
Analytics
We collect anonymous usage metrics to improve DeepFabric. No personal data, prompts, or API keys are collected.
# Disable analytics
export ANONYMIZED_TELEMETRY=False
Metadata
Release files for DeepFabric 4.2.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| deepfabric-4.2.1.tar.gz | 15.7 MB | With provenance | Details for deepfabric-4.2.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| deepfabric-4.2.1-py3-none-any.whl | Python 3 | none | any | Details for deepfabric-4.2.1-py3-none-any.whl |
Total release size: 15.9 MB
Release files / deepfabric-4.2.1.tar.gz
| Download URL | deepfabric-4.2.1.tar.gz |
|---|---|
| Size | 15.7 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
7c9246d6819a4814ceff52d12ad26839c7f2b302c54d3d204649706a3a4b83e7
|
|
BLAKE2b-256 checksum How to use checksums |
a0e4e574ec74cd66651dcb4b390f49bfafc6cc7ba831fbd62a81c137aa7f4797
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Dec 8, 2025.
Transparency logRelease files / deepfabric-4.2.1-py3-none-any.whl
| Download URL | deepfabric-4.2.1-py3-none-any.whl |
|---|---|
| Size | 156.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
abbbca1abeffd00c37f553261654e74da19e524226dd40b9a78ec8bd26f12d33
|
|
BLAKE2b-256 checksum How to use checksums |
ee91eb73c40b654521595ae2ef9c3a3f72d80b28cef9345d39c07b641a1f7e61
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Dec 8, 2025.
Transparency logSecurity for DeepFabric 4.2.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for deepfabric-4.2.1.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Dec 8, 2025.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.