/synthetic-data:real-to-synth-llmfrom synthetic-data
Transform real text records into synthetic counterparts that preserve semantics while changing specifics, with any LLM route.
Ships in synthetic-data. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
Convert real unstructured or semi-structured text records into synthetic counterparts that preserve semantic intent and structure while replacing all personally identifiable, datable, and location-specific details. Uses an LLM to intelligently rewrite records with explicit "preserve / change" rules.
./synthetic-data-workspace/outputs/)Dependencies are inline in each script (uv run --with scikit-learn --with numpy check_leakage.py); no install step.
Draft a transformation prompt with explicit rules:
You are anonymising {record_type} for research/testing purposes.
Read this real record:
{real_record_json}
Rewrite it as a synthetic record following these rules:
- PRESERVE: semantic intent, tone, structure, technical content, logical flow
- PRESERVE: {preservation_rules}
- CHANGE: all names, places, dates, email addresses, phone numbers, URLs, IDs
- CHANGE: specific quoted text, proper nouns, organizational names
- MAINTAIN: field schema, word count approximately
Return only valid JSON, no markdown.
Build jobs and run them on any route (read the overlay preferences.md first for route, models, budget; see generate-text-data). One job per real record; the runner is resumable and vendor-agnostic:
# make_jobs.py (run: uv run make_jobs.py real.jsonl > jobs.jsonl)
# /// script
# dependencies = ["pandas"]
# ///
import json, sys
import pandas as pd
path = sys.argv[1]
rows = ([json.loads(l) for l in open(path)] if path.endswith(".jsonl")
else pd.read_csv(path).to_dict(orient="records"))
TEMPLATE = open("prompt.txt").read() # the prompt from step 2 with {real_record_json}
for i, r in enumerate(rows):
print(json.dumps({"id": str(i), "prompt": TEMPLATE.replace("{real_record_json}", json.dumps(r, ensure_ascii=False))}))
uv run "${CLAUDE_PLUGIN_ROOT}/scripts/llm_generate.py" jobs.jsonl --out synth_raw.jsonl \
--route <route> --models <model> --workers 4 --limit 10 # pilot, then drop --limit
Parse each output as JSON (strip markdown fences), drop and count failures. Real data goes only to a route the user approves for it; for sensitive records prefer a local route (--route ollama).
Optional: QA check for leakage (flag records too similar to source):
import numpy as np
from sklearn.feature_extraction.text import TfidfVectorizer
from sklearn.metrics.pairwise import cosine_similarity
def check_leakage(real_path, synth_path, threshold=0.75):
with open(real_path) as f:
real_records = [json.loads(line) for line in f]
with open(synth_path) as f:
synth_records = [json.loads(line) for line in f]
# Concatenate all text fields
real_texts = [' '.join(str(v) for v in r.values()) for r in real_records]
synth_texts = [' '.join(str(v) for v in r.values()) for r in synth_records]
vectorizer = TfidfVectorizer()
all_texts = real_texts + synth_texts
tfidf = vectorizer.fit_transform(all_texts)
flagged = []
for i, synth_idx in enumerate(range(len(real_texts), len(all_texts))):
similarity = cosine_similarity(tfidf[synth_idx], tfidf[:len(real_texts)])
max_sim = np.max(similarity)
if max_sim > threshold:
flagged.append({
'synthetic_record_idx': i,
'max_similarity': float(max_sim),
'closest_real_idx': int(np.argmax(similarity))
})
if flagged:
print(f"Flagged {len(flagged)} records with similarity > {threshold}")
for f in flagged[:5]:
print(f" Record {f['synthetic_record_idx']}: similarity={f['max_similarity']:.3f}")
else:
print(f"All {len(synth_records)} records passed leakage check (similarity < {threshold})")
return flagged
Run transformation and QA:
uv run --with scikit-learn --with numpy check_leakage.py # Optional QA
What SKILL.md sets; muted values are Claude Code's defaults
13 skills in this plugin
/check-diversityMeasure how repetitive a generated text set is (trigram Jaccard, top-word share, per-model breakdown) and remove near-duplicates. Use on "is this too samey", "dedupe the generated data", "diversity check", "check the pilot before scaling"./complementary-pluginsList and install plugins that complement synthetic-data: custom-model-planning, data-annotation. Use on "related plugins"./evaluate-qualityRun fidelity, utility, and privacy diagnostics on a synthetic dataset against the real source, generating a markdown report.Other plugins' skills for the same job
synthetic-data@danielrosehill is listed by danielrosehill/claude-code-plugins — review the source before installing
npx claudepluginhub danielrosehill/claude-code-plugins --plugin synthetic-data