agentleFS
always-furtheralways-further/deepfabric/CLAUDE.md

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
  1. Very specific:

    Test files are in tests/ directory

    line 27
  2. Very specific:

    Verify that subtopics_list receives the complete path, never the target topic text alone when hierarchical context is available.

    line 74
  3. Distinctive:

    do not place imports anywhere but the top of the file

    line 114
  4. Very specific:

    When updating docs/ documentation, if new Markdown files are added or removed, consider updating mkdocs.yml.

    line 115

≈ “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.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
CLAUDE.md

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:

  1. Tree: Generates hierarchical topic structures from a root prompt
  2. DataSetGenerator: Creates training examples based on topics
  3. Dataset: Manages and exports the final dataset

Development Commands

Package Management

  • uv sync --all-extras - Install all dependencies including dev tools
  • make install - Same as above via Makefile

Code Quality

  • make format - Format code with black and ruff auto-fix
  • make lint - Run ruff linting checks
  • make security - Run bandit security analysis on deepfabric/ directory

Testing

  • make test - Run pytest test suite
  • uv run pytest - Direct pytest execution
  • Test files are in tests/ directory

Build and Release

  • make build - Clean, test, and build package
  • make clean - Remove build artifacts and cache files
  • make 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

  1. Tree generates topic hierarchy from root prompt
  2. DataSetGenerator uses topics to create question/answer pairs
  3. Dataset validates, stores, and exports training examples
  4. Optional HuggingFace Hub upload with auto-generated dataset cards

Key Classes and Their Relationships

  • DeepFabricConfig: Loads YAML and provides argument objects
  • TreeArguments/DataSetGeneratorArguments: Pydantic-style dataclasses for parameters
  • Dataset: Handles JSONL import/export and validation
  • HFUploader: 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, and Graph.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: {...}  # optional

Provider 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/dataset

Code 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 updating mkdocs.yml.

Download now (ZIP)

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
What did you use it for? e.g. Reviewing pull requests in a Rails app

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.