Skip to main content

coreason-synthesis

Grounded Synthetic Data Generation (SDG) for the CoReason-AI platform.

License Build Status Code Style: ruff Documentation

Overview

coreason-synthesis is the "Amplifier" of the CoReason platform. It solves the "Cold Start Problem" of evaluation by manufacturing high-quality, domain-specific Benchmark Evaluation Corpora (BEC) from a small set of user-provided examples.

Unlike standard GenAI approaches that rely on hallucination, this library implements a Grounded Synthesis Pipeline:

  1. Learns the testing pattern from user-provided Seeds.
  2. Forages for real, semantically similar documents via MCP.
  3. Extracts verbatim text slices (The "Real Data").
  4. Composites synthetic questions around that data (The "Fake Scenario").
  5. Appraises and ranks the results by complexity and diversity.

The output is a rigorous, stratified test suite that validates the agent against actual enterprise data variances, not idealized synthetic text.

Features

  • Pattern-Forage-Fabricate-Rank Loop: A complete pipeline for generating high-quality test data.
  • Server Mode: Run as a high-concurrency FastAPI microservice.
  • Docker Ready: Containerized for production deployment.
  • Few-Shot Intent Inference: Infers testing intent from a few examples.
  • Verbatim Defense: Uses pixel-perfect copies of real data (preserving errors/formatting) as context.
  • Lineage Transparency: Distinguishes between "Verbatim/Real" and "Adversarial/Perturbed" data.
  • Quality Ranking: Appraises and ranks cases by complexity, ambiguity, diversity, and validity.
  • Safety & Privacy: Includes PII Sanitization filters.

For detailed requirements and specifications, see docs/product_requirements.md.

Installation

pip install coreason-synthesis

Running as a Service

You can run coreason-synthesis as a standalone microservice using Docker or directly via Uvicorn.

1. Docker (Recommended)

# Build the image
docker build -t coreason-synthesis .

# Run the container
docker run -p 8000:8000 \
  -e OPENAI_API_KEY="sk-..." \
  -e MCP_BASE_URL="http://mcp-service:8080" \
  coreason-synthesis

2. Manual Execution

# Install dependencies
pip install coreason-synthesis[server]

# Export credentials
export OPENAI_API_KEY="sk-..."
export MCP_BASE_URL="http://localhost:8080"

# Start the server
uvicorn coreason_synthesis.server:app --host 0.0.0.0 --port 8000

Usage (Library Mode)

Here is a concise example of how to initialize and use the library (using built-in mocks for demonstration):

import uuid
from coreason_synthesis.pipeline import SynthesisPipeline
from coreason_synthesis.analyzer import PatternAnalyzerImpl
from coreason_synthesis.forager import ForagerImpl
from coreason_synthesis.extractor import ExtractorImpl
from coreason_synthesis.compositor import CompositorImpl
from coreason_synthesis.perturbator import PerturbatorImpl
from coreason_synthesis.appraiser import AppraiserImpl
from coreason_synthesis.models import SeedCase, Document

# Import mocks for demonstration (replace with real implementations in prod)
from coreason_synthesis.mocks.teacher import MockTeacher
from coreason_synthesis.mocks.embedding import DummyEmbeddingService
from coreason_synthesis.mocks.mcp import MockMCPClient

# 1. Initialize Dependencies
teacher = MockTeacher()
embedder = DummyEmbeddingService()
mcp_client = MockMCPClient(
    documents=[
        Document(
            content="Standard Dose: 50mg. Included: Adults.",
            source_urn="doc:1"
        )
    ]
)

# 2. Initialize Components
analyzer = PatternAnalyzerImpl(teacher, embedder)
forager = ForagerImpl(mcp_client, embedder)
extractor = ExtractorImpl()
compositor = CompositorImpl(teacher)
perturbator = PerturbatorImpl()
appraiser = AppraiserImpl(teacher, embedder)

# 3. Assemble Pipeline
pipeline = SynthesisPipeline(
    analyzer=analyzer,
    forager=forager,
    extractor=extractor,
    compositor=compositor,
    perturbator=perturbator,
    appraiser=appraiser
)

# 4. Define Seeds
seeds = [
    SeedCase(
        id=uuid.uuid4(),
        question="Calculate BSA for 180cm, 80kg patient",
        expected_output={"bsa": 2.0},
        context="Formula: sqrt((height*weight)/3600)"
    )
]

# 5. Run Synthesis
config = {
    "target_count": 5,
    "perturbation_rate": 0.5,
    "sort_by": "complexity_desc"
}
user_context = {"user_id": "demo-user"}

results = pipeline.run(seeds, config, user_context)

# 6. Use Results
for case in results:
    print(f"Generated Case ({case.provenance}): {case.synthetic_question}")

Metadata

Release files for coreason-synthesis 0.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for coreason-synthesis 0.3.0
File Size Uploaded
coreason_synthesis-0.3.0.tar.gz 29.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for coreason-synthesis 0.3.0
File Interpreter ABI Platform
coreason_synthesis-0.3.0-py3-none-any.whl Python 3 none any Details

Total release size: 73.3 kB

Release files / coreason_synthesis-0.3.0.tar.gz

Download URL coreason_synthesis-0.3.0.tar.gz
Size 29.5 kB
Tags Source
SHA-256 checksum
How to use checksums
8326b948f7c15a7b7545f5d8a2de8c43af3f15c5939b3b5453640826bee7237f
BLAKE2b-256 checksum
How to use checksums
e403756e7d07452eca672ecd9ab2c8a8a153ce691d2d2f5037c1cc706d99ace4
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 Jan 30, 2026.

Transparency log

Release files / coreason_synthesis-0.3.0-py3-none-any.whl

Download URL coreason_synthesis-0.3.0-py3-none-any.whl
Size 43.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3b299766dbd12f3b278c641556ba4e6fee6877acf3fb8c74d760c2d8d5321f7c
BLAKE2b-256 checksum
How to use checksums
db98b8cb99b85cc09640dda0480d0ee9585761c4219d25c7c689cd7748cfc1a5
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 Jan 30, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.3.0 This release

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page