deepfabric
CLAUDE.md895 starsChanged 8 months agoApache-2.0View on GitHub
DeepFabric is a Python library for generating synthetic datasets using LLM providers. It consists of three main components that work together in a pipeline: Graph generation targets every non-root node, so interior nodes are generation targets in their own right, not merely waypoints on a route to a leaf. Cycle-based generation resolves each unique topic through TopicModel.get_path_by_id(). Graph overrides this method to follow first-parent ancestry; Tree uses the inherited lookup over enumerated leaf paths. Two distinct questions, two distinct methods…
The file
We split this CLAUDE.md into the rules it gives an agent
4 rules. About 0 are common, 1 is distinctive, and 3 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈1
Distinctive · estimate
This author's own choices. Worth a look.
3
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 27
Test files are in tests/ directory
- Very specific: line 74
Verify that subtopics_list receives the complete path, never the target topic text alone when hierarchical context is available.
- Distinctive: line 114
do not place imports anywhere but the top of the file
- Very specific: line 115
When updating docs/ documentation, if new Markdown files are added or removed, consider updating mkdocs.yml.
≈ “Common” is an estimate: at least 1 in 5 of the 26,980 CLAUDE.md files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
CLAUDE.md
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
Project Overview
DeepFabric is a Python library for generating synthetic datasets using LLM providers. It consists of three main components that work together in a pipeline:
- Tree: Generates hierarchical topic structures from a root prompt
- DataSetGenerator: Creates training examples based on topics
- Dataset: Manages and exports the final dataset
Development Commands
Package Management
uv sync --all-extras- Install all dependencies including dev toolsmake install- Same as above via Makefile
Code Quality
make format- Format code with black and ruff auto-fixmake lint- Run ruff linting checksmake security- Run bandit security analysis on deepfabric/ directory
Testing
make test- Run pytest test suiteuv run pytest- Direct pytest execution- Test files are in
tests/directory
Build and Release
make build- Clean, test, and build packagemake clean- Remove build artifacts and cache filesmake all- Complete workflow: install, format, lint, test, security, build
Core Architecture
Configuration System
- YAML-based configuration with direct system prompt specification
- CLI supports extensive parameter overrides
Data Flow
- Tree generates topic hierarchy from root prompt
- DataSetGenerator uses topics to create question/answer pairs
- Dataset validates, stores, and exports training examples
- Optional HuggingFace Hub upload with auto-generated dataset cards
Key Classes and Their Relationships
DeepFabricConfig: Loads YAML and provides argument objectsTreeArguments/DataSetGeneratorArguments: Pydantic-style dataclasses for parametersDataset: Handles JSONL import/export and validationHFUploader: Manages Hugging Face Hub integration
Important Implementation Details
JSON Validation
The engine includes robust JSON parsing with regex extraction and retry logic for handling LLM response inconsistencies.
Error Handling
- Max retries configurable for failed LLM calls
- Failed samples tracked separately from successful ones
- Comprehensive error reporting in final summary
Topic Path Context in Generation
Dataset generation must pass the full hierarchical path to the target topic (root → ... → topic) to build_prompt(), including when the target is an interior graph node. The full path provides essential context for the LLM to generate domain-specific samples.
Graph generation targets every non-root node, so interior nodes are generation targets in their own right, not merely waypoints on a route to a leaf.
Cycle-based generation resolves each unique topic through TopicModel.get_path_by_id(). Graph overrides this method to follow first-parent ancestry; Tree uses the inherited lookup over enumerated leaf paths.
Two distinct questions, two distinct methods - do not substitute one for the other:
get_path_by_id(uuid)- "what is this node's ancestry?" Resolves any node, interior ones included, by walking first parents to the root. A node with several parents gets one canonical ancestry via its first parent (the primary expansion parent; cross-connections are appended after it).get_all_paths_with_ids()- "what are the root-to-leaf routes?" Enumerates complete routes, keyed by leaf UUID. It cannot answer ancestry for an interior node, andGraph.get_path_by_id()does not call it.
Verify that subtopics_list receives the complete path, never the target topic text alone when hierarchical context is available.
System Message Control
The sys_msg parameter controls whether system messages are included in the final dataset format - this affects training data structure.
Configuration Patterns
YAML Structure
dataset_system_prompt: "..."
topic_tree:
args: {...}
save_as: "file.jsonl"
data_engine:
args: {...}
dataset:
creation: {...}
save_as: "file.jsonl"
huggingface: {...} # optionalProvider Configuration
Specify provider and model separately in config, or use combined format in code:
- Config:
provider: "ollama",model: "mistral:latest" - Code:
model_name: "ollama/mistral:latest"
CLI Usage Patterns
The CLI supports both YAML configuration and parameter overrides:
deepfabric start config.yaml --model gpt-4 --temperature 0.8 --hf-repo user/datasetCode Style Notes
- Uses uv for dependency management
- Ruff for linting with extensive rule set
- Black for formatting
- Bandit for security analysis
- Python 3.11+ required
- Google-style docstrings preferred
- do not place imports anywhere but the top of the file
- When updating
docs/documentation, if new Markdown files are added or removed, consider updatingmkdocs.yml.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

