Distill-Align: The Structured Reasoning Extraction Factory
A CLI/Python framework that automates the generation of high-quality, fine-tuning datasets from raw domain data. It utilizes high-context frontier reasoning models as teachers, captures their deep thinking traces, and filters/prunes those traces into highly structured instruction-following formats optimized for fine-tuning.
π Ψ§ΩΨΉΨ±Ψ¨ΩΨ©: README.ar.md β Ψ§ΩΨͺΨ±Ψ¬Ω Ψ© Ψ§ΩΨΉΨ±Ψ¨ΩΨ© ΩΩΨ°Ψ§ Ψ§ΩΨ―ΩΩΩ.
π Full documentation: omargargoum.github.io/Distill-Align
- Smart Ingestion: Async chunking pipelines with semantic-aware splitting for Markdown and Code (PDF, DOCX, HTML, CSV, JSON, Jupyter notebooks, and web pages also supported). v0.2 adds semantic, parent-child (small-to-big), and late-contextual chunkers, table row-sentence serialization, and an optional Docling parser.
- Multi-Provider Synthesis: Supports OpenAI, Ollama, vLLM, Anthropic Claude, Google Gemini, and Azure OpenAI backends with async worker pools β plus 2026 gateways (OpenRouter, LiteLLM, Together, Groq, Mistral, DeepSeek, Cohere) and strict structured outputs per provider.
- Socratic Transformer: Converts raw reasoning into structured, multi-turn conversational Q&A. v0.2 adds Evol-Instruct, RAG-QA (grounded), tool-call/agent traces, Constitutional safety, and distillation-trace modes.
- Scaffold Action Pruner: Strips conversational filler to extract pure tool-calling or structural output.
- LLM-as-Judge Evaluation (optional): Automated quality scoring of generated conversations using a separate judge model, with confidence scores normalized 0β1. v0.2 adds faithfulness/groundedness rubrics, dual-judge (gate + audit), and a
distill-align evaluateCI gate with contamination checks. - Preference Generation: Create pairs for DPO β plus KTO (unpaired labels), ORPO (single-stage), and GRPO-ready groups with verifiable-reward stubs.
- Multiple Export Formats: ShareGPT, Alpaca, ChatML, HuggingFace messages (JSONL/JSON), KTO, GRPO, agent trajectories, RAG-QA, streaming JSON Lines, and Apache Parquet.
- Streaming Export: Export large datasets without loading them entirely into memory using iterative producers.
- Cost Tracking: Pay-as-you-go cost estimation and tracking across all providers with per-request token accounting.
- Unsloth Integration: Auto-generates optimized
train.pyscripts for Unsloth fine-tuning. - Rich TUI: Interactive terminal dashboard for monitoring pipeline execution.
pip install distill-align
# With optional dependencies
pip install distill-align[parquet] # Parquet export support
pip install distill-align[hub] # HuggingFace Hub integration
pip install distill-align[all] # All extraspip install --upgrade distill-alignpip uninstall distill-aligndistill-align --version
distill-align --helpA production-ready Docker image is available:
# Build locally
docker build -t distill-align .
# Run
docker run --rm -v "$(pwd):/app" distill-align --help
# Synthesize with mounted volumes
docker run --rm \
-v "$(pwd)/data:/app/data" \
-v "$(pwd)/output:/app/output" \
-e OPENAI_API_KEY="sk-..." \
distill-align synthesize \
--input /app/data/chunks.json \
--output /app/output/conversations.json \
--provider openai \
--model gpt-5-miniDistill-Align can be configured via three layers (highest priority first):
- CLI arguments β flags passed at runtime
- Environment variables β prefixed with
DISTILL_ - Config file β YAML/TOML file generated via
distill-align init
Generate a config file to get started:
distill-align initπ Full configuration reference: docs/configuration.md
export DISTILL_LLM_PROVIDER=openai
export DISTILL_LLM_MODEL=gpt-5-mini
export DISTILL_LLM_API_KEY=sk-...
export DISTILL_LOG_LEVEL=INFO| Variable | Required For | Description |
|---|---|---|
OPENAI_API_KEY |
OpenAI / Azure | OpenAI API key |
ANTHROPIC_API_KEY |
Anthropic | Anthropic API key |
GOOGLE_API_KEY |
Google Gemini | Google AI Studio API key |
AZURE_OPENAI_API_KEY |
Azure OpenAI | Azure OpenAI resource key |
AZURE_OPENAI_ENDPOINT |
Azure OpenAI | Azure OpenAI endpoint URL |
DASHSCOPE_API_KEY |
Qwen | Alibaba DashScope API key |
DEEPSEEK_API_KEY |
DeepSeek | DeepSeek API key |
MISTRAL_API_KEY |
Mistral | Mistral La Plateforme key |
OPENROUTER_API_KEY |
OpenRouter | OpenRouter gateway key |
DISTILL_LLM_API_KEY |
Any provider | Generic override (takes precedence) |
# Ingest and process data
distill-align ingest --source ./my-docs --output ./chunks.json
# Synthesize conversations (with judge evaluation)
distill-align synthesize \
--input ./chunks.json \
--output ./conversations.json \
--provider openai \
--model gpt-5-mini \
--judge \
--judge-model gpt-5-nano
# Export to training format
distill-align export \
--input ./conversations.json \
--format hf_messages \
--output ./dataset
# Generate preference pairs for DPO training
distill-align export \
--input ./conversations.json \
--format preference \
--output ./dpo-pairs
# Zero-LLM quality gate (CI-friendly) with contamination check
distill-align evaluate \
--input ./conversations.json \
--threshold 0.5
# Serve the REST API (requires the serve extra)
distill-align serve --port 8000
# Launch TUI
distill-align tui| Provider | SDK-Free | Structured Output | Auth |
|---|---|---|---|
| OpenAI | β | β (strict) | API key |
| Anthropic | β | β (output_config, GA) |
API key |
| Google Gemini | β | β (responseSchema) |
API key |
| Azure OpenAI | β | β | API key or Entra ID (OAuth2) |
| Ollama | β | β (schema format) |
None (local) |
| vLLM | β | β (guided_json) |
None / API key |
| OpenRouter | β | β (gateway) | API key |
| LiteLLM proxy | β | β (gateway) | API key / none (self-host) |
| Together/Groq/Mistral/DeepSeek/Cohere | β | β (gateway) | API key |
| Format | Extension | Description |
|---|---|---|
hf_messages |
.jsonl |
HuggingFace messages format (JSONL recommended) |
jsonl |
.jsonl |
Generic JSON Lines (streaming-capable) |
parquet |
.parquet |
Columnar format (requires pyarrow) |
sharegpt |
.json |
ShareGPT conversation format |
alpaca |
.json |
Alpaca instruction format |
chatml |
.json |
ChatML markup format |
conversation |
.json |
Raw conversation schema export |
preference |
.json |
DPO preference pairs (requires judge scores) |
dpo / orpo |
.json |
DPO / ORPO triples (score-aware when judged) |
kto |
.json |
KTO unpaired rows (prompt/completion/label) |
grpo |
.json |
GRPO groups (prompt/completions/rewards) |
agent |
.json |
Agent / tool-call trajectories |
rag_qa |
.json |
Grounded RAG-QA rows (doubles as retrieval eval) |
This project follows a Modular Monolith architecture.
distill-align/
βββ src/distill_align/ # Core application package
β βββ core/ # Config, schemas, logging, caching, checkpointing
β βββ ingestion/ # Data loaders and chunkers (PDF, DOCX, HTML, code, etc.)
β βββ synthesis/ # LLM clients, worker pool, prompts, judge, cost tracking
β β βββ models/ # Provider-specific clients (OpenAI, Anthropic, Gemini, Azure, Ollama, vLLM)
β βββ exporter/ # Formatters, validator, splitter, preference generator
β β βββ formatters/ # Output format converters (JSONL, Parquet, ShareGPT, Alpaca, etc.)
β βββ tui/ # Textual terminal UI
β βββ cli/ # Typer CLI entry points
βββ tests/ # Pytest suite
βββ docs/ # Documentation (MkDocs)
- Clone the repository
- Install dependencies with Poetry:
poetry install - Install dev dependencies:
poetry install --with dev - Run tests:
poetry run pytest - Run linting:
poetry run ruff check src/
MIT License - see LICENSE for details.