{"record":{"id":"75bcb68bf7271f5b","repo":"nautechsystems/nautilus_trader","slug":"unsupported-canonical-backtest-result-schema","errorCode":null,"errorMessage":"unsupported canonical backtest result schema","messagePattern":"unsupported canonical backtest result schema","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/backtest/src/result.rs","lineNumber":308,"sourceCode":"                \"total_positions\": state.total_positions.to_string(),\n                \"trader_id\": state.trader_id,\n            },\n            \"schema\": CANONICAL_SCHEMA,\n            \"statistics\": canonical_statistics(state.statistics),\n            \"summary\": state.summary,\n        });\n\n        canonicalize_document(&mut document)?;\n        validate_document(&document)?;\n        Ok(Self { document })\n    }\n}\n\nfn validate_document(document: &Value) -> anyhow::Result<()> {\n    let object = document\n        .as_object()\n        .ok_or_else(|| anyhow::anyhow!(\"canonical backtest result must be a JSON object\"))?;\n    anyhow::ensure!(\n        object.get(\"schema\").and_then(Value::as_str) == Some(CANONICAL_SCHEMA),\n        \"unsupported canonical backtest result schema\"\n    );\n    let fields = [\n        \"accounts\",\n        \"components\",\n        \"diagnostics\",\n        \"fills\",\n        \"orders\",\n        \"portfolio_snapshots\",\n        \"position_snapshots\",\n        \"positions\",\n        \"run\",\n        \"schema\",\n        \"statistics\",\n        \"summary\",\n    ];\n    validate_fields(object, &fields, \"canonical result\")?;","sourceCodeStart":290,"sourceCodeEnd":326,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/backtest/src/result.rs#L290-L326","documentation":"After confirming the document is an object, `validate_document` requires `object[\"schema\"]` to equal the supported canonical schema string (version 1). Any other value — different version string, missing field, or non-string — produces this error. It guards against loading results written by incompatible schema versions.","triggerScenarios":"Loading a backtest result whose `schema` field is absent, misspelled, or set to a different version (e.g. produced by an older/newer format) via `from_slice` or `from_state`.","commonSituations":"Upgrading or downgrading the library so saved results use a schema version no longer accepted; hand-editing the schema field; a custom producer forgetting to set `schema`.","solutions":["Set/regenerate the document so `schema` equals the supported canonical value (version 1 string used by the library)","Migrate old-format results to the current schema before loading, or re-run the backtest to produce current-format results","Check that the file is the canonical result document, not an intermediate or legacy export","Verify no post-processing step rewrote or dropped the `schema` field"],"exampleFix":"// before\n{\"schema\": \"nautilus.backtest.v0\", ...}\n// after\n{\"schema\": \"nautilus.backtest.v1\", ...} // exact CANONICAL_SCHEMA string supported by this version","handlingStrategy":"validation","validationCode":"doc = json.load(open(path))\nassert doc.get(\"schema\") == EXPECTED_SCHEMA, f\"unsupported schema: {doc.get('schema')}\"","typeGuard":"fn has_supported_schema(doc: &serde_json::Value) -> bool {\n    doc.get(\"schema\").and_then(|v| v.as_str()) == Some(CANONICAL_SCHEMA)\n}","tryCatchPattern":"match BacktestResult::from_slice(&bytes) {\n    Err(e) if e.to_string().contains(\"unsupported canonical backtest result schema\") => {\n        eprintln!(\"schema version mismatch — migrate or re-run: {e:#}\");\n    }\n    Err(e) => return Err(e),\n    Ok(r) => r,\n}","preventionTips":["Pin the library version used to write and read result files","Record the schema version alongside archives and write migration steps for upgrades","Never edit the schema field by hand"],"tags":["schema","versioning","backtest","compatibility"],"backgroundTag":"schema-validation-failed","analyzedSha":"18893faf8b356be3320add8de2f861b0b647cf06","analyzedAt":"2026-09-08T20:49:34.690Z","contentChangedAt":"2026-09-08T20:49:34.690Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}