so i’ve been working on an agentic data migration harness that combines deterministic code and llm judgement to auto migrate csv files such as this example here. the tool can work with any master or transaction data:
Customer Name,Customer Type,Group,Territory,Contact Name,Email,Phone,Address Type,Address Line 1,City,State,Postal Code,Country,Tax ID,Website,Loyalty Tier,Customer Since
Acme Steel Works,Company,Commercial,All Territories,Alicia Henderson,[email protected],+1 555 2100,Billing,100 Foundry Way,Cleveland,Ohio,44101,United States,US-11-22-3333,https://acmesteel.example,Gold,2015-03-12
Acme Steel Works,Company,Commercial,All Territories,Alicia Henderson,[email protected],+1 555 2100,Shipping,200 Dockside Ave,Cleveland,Ohio,44102,United States,,,,
Maple Grove Organics,Individual,Commercial,United States,Carla Ng,[email protected],,Billing,7 Orchard Ln,Sacramento,California,95814,United States,,https://maplegrove.example,Silver,2018-07-01
Ironclad Fasteners Co,Company,Commercial,All Territories,Ravi Patel,[email protected],+1 555 4100,Billing,55 Rivet Rd,Akron,Ohio,44306,United States,US-44-55-6666,,Bronze,
Prairie Wind Machinery,Company,Commercial,All Territories,Sam Reyes,[email protected],+1 555 4102,Office,12 Plains Hwy,Omaha,Nebraska,68102,United States,,,,2020-01-15
Falcon Ridge Plastics,Company,Commercial,All Territories,Gina Alvarez,[email protected],+1 555 4105,Billing,300 Polymer Pkwy,Detroit,Michigan,48201,United States,,,,
Blackwater Steel Supply,Company,Commercial,United States,Dana Whitfield,[email protected],+1 555 4101,Billing,88 Ingot Ln,Pittsburgh,Pennsylvania,15201,United States,,,,
Copperline Electric,Company,Commercial,Rest Of The World,Oliver Chen,[email protected],+44 20 555 4103,Billing,14 Copper Row,Manchester,,M1 2AB,United Kingdom,,,,
Sterling Oak Furniture,Company,Commercial,United States,Margaret Doyle,[email protected],+1 555 4104,Office,9 Cabinet St,Portland,Oregon,97205,United States,,,,
Granite Peak Mining Supply,Company,Commercial,All Territories,Hector Ruiz,[email protected],+1 555 4106,Billing,220 Quarry Rd,Butte,Montana,59701,United States,,,,
Harborview Marine Parts,Company,Commercial,United States,Nina Petrov,[email protected],+1 555 4107,Shipping,77 Pier Ave,Seattle,Washington,98107,United States,,,,
Juniper Textile Mills,Company,Commercial,All Territories,Aisha Khan,[email protected],+1 555 4108,Billing,31 Loom Way,Greensboro,North Carolina,27406,United States,,,,
Keystone Conveyor Co,Company,Commercial,All Territories,Walter Briggs,[email protected],+1 555 4109,Billing,600 Beltline Dr,Allentown,Pennsylvania,18103,United States,,,,
Lakeshore Beverage Group,Company,Commercial,United States,Priya Shah,[email protected],+1 555 4110,Billing,410 Soda Rd,Milwaukee,Wisconsin,53202,United States,,,,
Monarch Gear Works,Company,Government,All Territories,Raymond Holt,[email protected],+1 555 4111,Billing,900 Arsenal Way,Huntsville,Alabama,35805,United States,,,,
Northgate Industrial Supply,Company,Commercial,All Territories,Sofia Marino,[email protected],+1 555 4112,Billing,45 Fastener Blvd,Columbus,Ohio,43215,United States,,,,
Orchard Valley Foods,Company,Commercial,United States,Ethan Brooks,[email protected],+1 555 4113,Billing,120 Harvest Ln,Fresno,California,93720,United States,,,,
Polaris Hydraulics,Company,Commercial,All Territories,Iris Novak,[email protected],+1 555 4114,Billing,900 Pressure Ave,Minneapolis,Minnesota,55413,United States,,,,
Quicksilver Tooling,Company,Commercial,Rest Of The World,Jonas Weber,[email protected],+49 30 555 4115,Billing,5 Schneide Weg,Stuttgart,,70173,Germany,,,,
Redstone Fabrication,Company,Commercial,United States,Marco Silva,[email protected],+1 555 4116,Billing,300 Weld Rd,Houston,Texas,77020,United States,,,,
Sierra Filtration Systems,Company,Government,All Territories,Lena Okafor,[email protected],+1 555 4117,Billing,44 Filter Pkwy,Reno,Nevada,89501,United States,,,,
Timberline Pallet Works,Company,Commercial,All Territories,Owen Dale,[email protected],+1 555 4118,Billing,78 Timber Rd,Eugene,Oregon,97401,United States,,,,
Upstream Robotics,Individual,Commercial,United States,Casey Lin,[email protected],,Office,5 Automation Ct,Austin,Texas,78701,United States,,,,
Summit Forge Co,Company,Commercial,All Territories,Maria Flores,[email protected],+1 555 3100,Shipping,33 Forge Rd,Cleveland,Ohio,44114,United States,,,,
Cascade Auto Parts,Company,Commercial,All Territories,Tom Nguyen,[email protected],+1 555 3102,Billing,900 Motor Ave,Detroit,Michigan,48226,United States,,,,
Ironclad Fasteners Co,Company,Commercial,All Territories,Ravi Patel,[email protected],,Office,55 Rivet Rd,Akron,Ohio,44306,United States,,,,
Falcon Ridge Plastics,Company,Commercial,All Territories,Mark Alvarez,[email protected],+1 555 4200,Billing,300 Polymer Pkwy,Detroit,Michigan,48201,United States,,,,
Granite Bay Landscaping,Company,Commercial,United States,Colin Foster,,+1 555 4201,Billing,88 Garden Grove Rd,Roseville,California,95678,United States,,,,
,Company,Commercial,All Territories,Edge Contact,[email protected],+1 555 0001,Billing,1 Edge St,Edgeville,EdgeState,00000,EdgeCountry,,,,
Hollow Core Drilling,Company,Commercial,All Territories,Edge Driller,[email protected],+1 555 0002,Billing,,,,,,,,,
zshanhui@macbook data-migration % .venv/bin/python scripts/agent.py --source samples/customers-smb.csv
Starting agent for customers_full — 4 conflicts
[error ] unmapped_column Tax ID
[error ] unmapped_column Website
[error ] unmapped_column Loyalty Tier
[error ] unmapped_column Customer Since
=== Round 1/20 — 4 error conflict(s), 4 total ===
[error] unmapped_column: Tax ID
[error] unmapped_column: Website
[error] unmapped_column: Loyalty Tier
[error] unmapped_column: Customer Since
--- Round 1: 0 error(s) remain
=== AGENT CONVERGED (no error-severity conflicts) ===
All conflicts resolved and data imported successfully. Here's the summary:
## Migration Summary
**Source:** `samples/customers-smb.csv` → doctype `customers_full` (Customer + Contact + Address flat sheet, 30 rows)
### Conflicts resolved (4 error-severity)
| Column | Resolution | Action |
|---|---|---|
| Tax ID | extend_contract | `set_mapping → customer.tax_id` |
| Website | extend_contract | `set_mapping → customer.website` |
| Loyalty Tier | extend_contract | `set_mapping → customer.loyalty_program_tier` |
| Customer Since | create_custom_field | `create_field('Customer', 'Customer Since', 'Date')` → fieldname `customer_since`, then `set_mapping → customer.customer_since` |
> Note: the initial parallel `set_mapping` batch suffered a concurrent-write clobber that dropped the Tax ID override; I re-issued it sequentially and confirmed via `run_map` that **all 17 columns were mapped with zero conflicts and zero extra columns** before importing.
### Import (apply=True)
- **Customer:** 26 created, 3 skipped, 1 failed
- **Contact:** 26 created, 2 skipped
- **Address:** 27 created, 1 skipped, 1 failed
The two data warnings are source-data issues, not mapping problems: one row lacked a Customer Name (skipped), and one address row (Hollow Core Drilling) lacked required `address_line1`/`city` and was rejected with HTTP 417 — imports remain idempotent so these can be retried once source data is corrected.
### Verification
Spot-checked **Acme Steel Works** — all four extended columns landed correctly:
- `customer_since` = 2015-03-12 (new custom field)
- `tax_id` = US-11-22-3333
- `website` = https://acmesteel.example
- `loyalty_program_tier` = Gold
26 customers, 26 contacts, and 27 addresses now exist in the system.
Agent transcript (thinking + tool calls + responses): /Users/zshanhui/oss/nyauto/erpgen/data-migration/logs/agent-customers_full-20260909-174623647281.jsonl
deterministic code creates an analysis json file which is feed into an LLM agent loop, that fixes the conflicts that was surfaced until everything is cleaned and it converges:
{
"schema_version": 1,
"generated_at": "2026-09-09T17:24:08+00:00",
"doctype": "customers_full",
"source": "samples/customers-smb.csv",
"source_rows": 30,
"base_url": "http://localhost:8082",
"known_mappings": [
{
"header": "Customer Name",
"doctype": "customer",
"target": "customer_name",
"method": "flat_contract"
},
{
"header": "Customer Type",
"doctype": "customer",
"target": "customer_type",
"method": "flat_contract"
},
{
"header": "Group",
"doctype": "customer",
"target": "customer_group",
"method": "flat_contract"
},
{
"header": "Territory",
"doctype": "customer",
"target": "territory",
"method": "flat_contract"
},
{
"header": "Contact Name",
"doctype": "contact",
"target": "contact_name",
"method": "flat_contract"
},
{
"header": "Email",
"doctype": "contact",
"target": "email",
"method": "flat_contract"
},
{
"header": "Phone",
"doctype": "contact",
"target": "phone",
"method": "flat_contract"
},
{
"header": "Address Type",
"doctype": "address",
"target": "address_type",
"method": "flat_contract"
},
{
"header": "Address Line 1",
"doctype": "address",
"target": "address_line1",
"method": "flat_contract"
},
{
"header": "City",
"doctype": "address",
"target": "city",
"method": "flat_contract"
},
{
"header": "State",
"doctype": "address",
"target": "state",
"method": "flat_contract"
},
{
"header": "Postal Code",
"doctype": "address",
"target": "pincode",
"method": "flat_contract"
},
{
"header": "Country",
"doctype": "address",
"target": "country",
"method": "flat_contract"
}
],
"extra_columns": [
{
"header": "Tax ID",
"non_empty": 0.067,
"sample": [
"US-11-22-3333",
"US-44-55-6666"
],
"inferred_type": "text",
"best_match": {
"doctype": "Customer",
"target": "tax_id",
"label": "Tax ID",
"score": 1.0,
"method": "exact"
},
"resolution": "extend_contract"
},
{
"header": "Website",
"non_empty": 0.067,
"sample": [
"https://acmesteel.example",
"https://maplegrove.example"
],
"inferred_type": "text",
"best_match": {
"doctype": "Customer",
"target": "website",
"label": "Website",
"score": 1.0,
"method": "exact"
},
"resolution": "extend_contract"
},
{
"header": "Loyalty Tier",
"non_empty": 0.1,
"sample": [
"Gold",
"Silver",
"Bronze"
],
"inferred_type": "text",
"best_match": {
"doctype": "Customer",
"target": "loyalty_program_tier",
"label": "Loyalty Program Tier",
"score": 0.85,
"method": "token"
},
"resolution": "extend_contract"
},
{
"header": "Customer Since",
"non_empty": 0.1,
"sample": [
"2015-03-12",
"2018-07-01",
"2020-01-15"
],
"inferred_type": "date",
"best_match": null,
"resolution": "create_custom_field",
"suggested_doctype": "Customer"
}
],
"column_profiles": [
{
"header": "Customer Name",
"non_empty": 0.967,
"unique": 0.897,
"sample": [
"Acme Steel Works",
"Maple Grove Organics",
"Ironclad Fasteners Co",
"Prairie Wind Machinery",
"Falcon Ridge Plastics"
],
"inferred_type": "text",
"messy": []
},
{
"header": "Customer Type",
"non_empty": 1.0,
"unique": 0.067,
"sample": [
"Company",
"Individual"
],
"inferred_type": "text",
"messy": []
},
{
"header": "Group",
"non_empty": 1.0,
"unique": 0.067,
"sample": [
"Commercial",
"Government"
],
"inferred_type": "text",
"messy": []
},
{
"header": "Territory",
"non_empty": 1.0,
"unique": 0.1,
"sample": [
"All Territories",
"United States",
"Rest Of The World"
],
"inferred_type": "text",
"messy": []
},
{
"header": "Contact Name",
"non_empty": 1.0,
"unique": 0.933,
"sample": [
"Alicia Henderson",
"Carla Ng",
"Ravi Patel",
"Sam Reyes",
"Gina Alvarez"
],
"inferred_type": "text",
"messy": []
},
{
"header": "Email",
"non_empty": 0.967,
"unique": 0.931,
"sample": [
"[email protected]",
"[email protected]",
"[email protected]",
"[email protected]",
"[email protected]"
],
"inferred_type": "text",
"messy": []
},
{
"header": "Phone",
"non_empty": 0.9,
"unique": 0.963,
"sample": [
"+1 555 2100",
"+1 555 4100",
"+1 555 4102",
"+1 555 4105",
"+1 555 4101"
],
"inferred_type": "text",
"messy": []
},
{
"header": "Address Type",
"non_empty": 1.0,
"unique": 0.1,
"sample": [
"Billing",
"Shipping",
"Office"
],
"inferred_type": "text",
"messy": []
},
{
"header": "Address Line 1",
"non_empty": 0.967,
"unique": 0.931,
"sample": [
"100 Foundry Way",
"200 Dockside Ave",
"7 Orchard Ln",
"55 Rivet Rd",
"12 Plains Hwy"
],
"inferred_type": "text",
"messy": []
},
{
"header": "City",
"non_empty": 0.967,
"unique": 0.828,
"sample": [
"Cleveland",
"Sacramento",
"Akron",
"Omaha",
"Detroit"
],
"inferred_type": "text",
"messy": []
},
{
"header": "State",
"non_empty": 0.9,
"unique": 0.556,
"sample": [
"Ohio",
"California",
"Nebraska",
"Michigan",
"Pennsylvania"
],
"inferred_type": "text",
"messy": []
},
{
"header": "Postal Code",
"non_empty": 0.967,
"unique": 0.931,
"sample": [
"44101",
"44102",
"95814",
"44306",
"68102"
],
"inferred_type": "text",
"messy": []
},
{
"header": "Country",
"non_empty": 0.967,
"unique": 0.138,
"sample": [
"United States",
"United Kingdom",
"Germany",
"EdgeCountry"
],
"inferred_type": "text",
"messy": []
},
{
"header": "Tax ID",
"non_empty": 0.067,
"unique": 1.0,
"sample": [
"US-11-22-3333",
"US-44-55-6666"
],
"inferred_type": "text",
"messy": []
},
{
"header": "Website",
"non_empty": 0.067,
"unique": 1.0,
"sample": [
"https://acmesteel.example",
"https://maplegrove.example"
],
"inferred_type": "text",
"messy": []
},
{
"header": "Loyalty Tier",
"non_empty": 0.1,
"unique": 1.0,
"sample": [
"Gold",
"Silver",
"Bronze"
],
"inferred_type": "text",
"messy": []
},
{
"header": "Customer Since",
"non_empty": 0.1,
"unique": 1.0,
"sample": [
"2015-03-12",
"2018-07-01",
"2020-01-15"
],
"inferred_type": "date",
"messy": []
}
],
"conflicts": [
{
"kind": "unmapped_column",
"severity": "info",
"source": "Tax ID",
"target": "tax_id",
"doctype": "Customer",
"detail": "Column 'Tax ID' is not in the flat contract but matches Customer.tax_id (exact, score 1.00).",
"suggested_action": "add 'Tax ID' -> Customer.tax_id to the customers_full contract so the values import."
},
{
"kind": "unmapped_column",
"severity": "info",
"source": "Website",
"target": "website",
"doctype": "Customer",
"detail": "Column 'Website' is not in the flat contract but matches Customer.website (exact, score 1.00).",
"suggested_action": "add 'Website' -> Customer.website to the customers_full contract so the values import."
},
{
"kind": "unmapped_column",
"severity": "info",
"source": "Loyalty Tier",
"target": "loyalty_program_tier",
"doctype": "Customer",
"detail": "Column 'Loyalty Tier' is not in the flat contract but matches Customer.loyalty_program_tier (token, score 0.85).",
"suggested_action": "add 'Loyalty Tier' -> Customer.loyalty_program_tier to the customers_full contract so the values import."
},
{
"kind": "unmapped_column",
"severity": "info",
"source": "Customer Since",
"detail": "Column 'Customer Since' has no matching field in Customer/Contact/Address.",
"suggested_action": "create a custom field on Customer (see suggested_custom_fields)."
}
],
"suggested_custom_fields": [
{
"source": "Customer Since",
"doctype": "Customer",
"fieldname": "customer_since",
"label": "Customer Since",
"fieldtype": "Date",
"reason": "unmapped non-empty source column (flat customers_full)",
"create_command": "python3 erpgen.py createfield Customer --label 'Customer Since' --fieldtype Date"
}
],
"agent_instructions": "You are the migration-fix agent for a flat customers_full sheet (Customer + Contact + Address in one file). The columns below are NOT in the fixed mapping contract and are dropped at import. Resolve each:\n- resolution=extend_contract -> add the header->field mapping to the customers_full contract so the values import into the matched field.\n- resolution=create_custom_field -> run the suggested create_command, then extend the contract to map the column to the new field.\nDo not import until every unmapped column is resolved."
}
it’s still wip, but i think the concept is pretty neat and could be useful in real world data migration projects from csv/excel/other erps?