Convert Tabular to Text
Convert tabular data into textual representations for use in LLM fine-tuning and evaluation experiments. This skill runs after design-experiment and before scaffold-experiment.
create-tabular-schema → design-experiment → convert-tabular-to-text → scaffold-experiment
Prerequisites
- Schema file must already exist in
ck-data/schemas/. If it doesn't, runcreate-tabular-schemafirst. - experiment_summary.yaml should exist (from design-experiment) for guided mode. Standalone usage is also supported.
Your Task
Walk the user through generating text datasets from tabular source data. Each invocation of the underlying convert.py tool produces one output file for one (condition x split) pair. This skill orchestrates multiple calls to produce all the files an experiment needs.
IMPORTANT: Throughout this workflow, create a detailed log at {experiment_dir}/logs/convert-tabular-to-text.log (or {scratch_dir}/ck-data/generated/logs/convert-tabular-to-text.log for standalone usage). Write entries incrementally as actions complete. See logging.md for the complete format specification and action types.
Step 1: Check for Existing Datasets
Ask: "Do you have existing generated datasets, or do we need to create new ones?"
Check ck-data/generated/ (under the user's scratch directory from claude.local.md) for any matching files:
ls {scratch_dir}/ck-data/generated/*.json 2>/dev/null
If the user has existing datasets, collect their paths and skip to Step 4.
Step 2: Load Schema
Load the schema from ck-data/schemas/:
ls {scratch_dir}/ck-data/schemas/ 2>/dev/null
If a matching schema exists: Load it and confirm with the user.
If no schema exists: Stop and advise the user to run create-tabular-schema first. The schema defines columns, types, and value maps that are needed for generation.
Step 3: Determine Template Style
If the user has an experiment_summary.yaml with a data_generation section:
The template style is already specified per condition. Read the template, template_file, and style_guidance fields from each condition. Confirm with the user: "The experiment design specifies [template types] — proceeding with those."
For each condition with template: narrative:
- If
template_fileis set: Use the specified template file. Verify it exists:
```bash
ls {template_file_path}
```
- If
template_fileis not set andstyle_guidanceis set: A custom template needs to be generated. Spawn thegenerate-jinja-templatesubagent (see below). - If neither
template_filenorstyle_guidanceis set: Use the built-in generic narrative template.
For each condition with template: llm_narrative:
- Confirm
ANTHROPIC_API_KEYis set andanthropicis installed. - Read
style_guidancefrom the condition (if present) — it will be passed as--style-guidanceat generation time. - A
--cache-pathshould be used in Step 6 for consistency across re-runs.
If no experiment_summary.yaml exists (standalone usage):
Present the available template styles (see design-experiment/references/tabular_to_text_gen.md for the full reference):
Which template style would you like?
1. Dictionary — Bulleted key-value pairs. Simple, explicit, no prose.
2. Narrative — Natural prose from a Jinja2 template.
- Do you have an existing Jinja2 template file, or would you like to generate one?
3. LLM narrative (
llm_narrative) — API-generated unique text per row. Non-deterministic. RequiresANTHROPIC_API_KEY.
If the user picks narrative without an existing template or llm_narrative, gather style preferences:
- Intended use — Fine-tuning, evaluation, or both? (Affects token density.)
- Style preference — Concise/dense or natural/verbose? Any specific tone?
- Any other guidance — e.g., avoid certain phrasings, emphasize particular features.
Generating Custom Narrative Templates
If a custom narrative template is needed (no template_file but style_guidance is present, or the user requests one in standalone mode), spawn the generate-jinja-template subagent:
Agent: generate-jinja-template
Prompt: Generate a Jinja2 narrative template for:
- Schema: {schema_path}
- Source data: {source_path}
- Output: {scratch_dir}/ck-data/templates/{dataset_name}.j2
- Features: {feature_list} (if known from experiment_summary.yaml)
- Intended use: {from style_guidance or user input}
- Style preference: {from style_guidance or user input}
- Additional instructions: {from style_guidance or user input}
When the agent returns:
- Show the user the generated template content and sample renderings
- Ask if they want any changes (if so, describe changes and re-run the agent, or edit the
.j2file directly) - Once approved, note the template path — it will be used as
--template-filein Step 6
Step 4: Determine Conditions
If the user has an experiment_summary.yaml with a data_generation section:
- Read conditions from
data_generation.conditions - Read shared settings (target, context, question, seed, split_ratio) from
data_generation
If no experiment_summary.yaml exists (standalone usage):
Walk the user through defining conditions. For each condition:
- Condition name — identifier (e.g.,
dict_full,dict_synonym,narrative_reduced) - Features — which columns to include (can differ per condition)
- Template —
dictionary,narrative, orllm_narrative - Perturbations — list from:
synonym,shorthand,reorder,clause_addition(can be empty)
Also gather shared settings:
- Target column and threshold or mapping
- Context text — the preamble/system prompt text
- Context placement —
preambleorsystem_prompt - Question text — the question appended to each entry
- Seed — random seed (default: 42)
- Split ratio — train fraction (default: 0.8)
- Subsampling ratio — fraction of source data to use, e.g., 0.33 for 33% (optional, omit to use all rows)
- Missing value handling —
skip(default) orinclude. Whenskip, NaN/missing feature values are omitted from the text. Wheninclude, they are represented with the missing value text. - Missing value text — text to use for missing values when handling is
include(default:missing). Examples:"missing","not reported","unknown".
Step 5: Determine Which Files to Generate
If an experiment_summary.yaml exists: Scan the runs list and evaluation matrix to determine which files are needed:
- Training conditions need
{train_condition}_train_{hash8}.json. The file contains both"train"and"validation"top-level keys —convert.pygenerates the bundle in a single invocation when passed--split trainalongside--validation-ratio. - Evaluation conditions need a separate test file:
{eval_condition}_test_{hash8}.json. This file contains only the"test"key. - Deduplicate: multiple runs may share the same train or test file.
Filename hash. Filenames include {hash8}, a content hash over the canonicalized generation config. If experiment_summary.yaml was produced by design-experiment, the hashed paths are already in each run's dataset_path / eval_dataset_path — read them directly. Otherwise, compute them with the shared helper as documented in