great expectations validation failed error: column type mismatch string vs int
Align the types before validating values: compare the column type in the warehouse information schema with the type the expectation assumes, find where values are written as strings, and cast at the model layer or fix the writer. Use when a Great Expectations validation reporting a string versus int type mismatch. Not for a mismatch caused by reading the wrong column entirely, which needs a mapping fix first.
TL;DR
Align the types before validating values: compare the column type in the warehouse information schema with the type the expectation assumes, find where values are written as strings, and cast at the model layer or fix the writer. Changing the expectation to accept strings hides a type drift that will break downstream numeric logic.
great expectations validation failed error: column type mismatch string vs intUse this when
- The check or run fails with this symptom: validation fails because a column arrives as string where int is expected.
- You are working on a Great Expectations validation reporting a string versus int type mismatch and the failure repeats on the same data or configuration.
- You need the failing rows, rule, or stage isolated before changing thresholds or code.
Not for this skill when
- A mismatch caused by reading the wrong column entirely, which needs a mapping fix first.
- The error text names a different tool, stage, or root cause. Match the verbatim error first and use that skill.
Steps
- Query the warehouse information schema for the column type and sample the distinct value shapes, including any non-numeric strings. Verify: the stored type and the offending value shapes are known
- Check the loader or model that writes the column for an implicit string cast, a CSV read without a schema, or a union that promotes values to string. Verify: the step that produces strings is identified
- Decide the contract: if the column is numeric, cast and validate at write time and quarantine non-numeric values; if it is genuinely textual, update the expectation and downstream consumers together. Verify: one contract is chosen and applied consistently
- Backfill or reload the affected partitions with the corrected type. Verify: the column reads back with the contracted type
- Rerun the validation suite and confirm the type expectation and value expectations both pass. Verify: the suite is green on the reloaded data
Variant phrasings
great expectations column type mismatch string vs int
The verbatim mismatch phrasing.
expectcolumnvaluestobeoftype failing string column
The type-expectation phrasing for of-type and in-set type checks.
warehouse column changed from int to string validation
The drift phrasing, where the writer changed the stored type.
Compatibility: Great Expectations 0.18 and 1.x with SQL datasources and inferred column types
Why it happens
Warehouses and file readers infer types per load, so one CSV with quoted numbers, one union branch, or one schema-on-read query can flip a column to string. Expectations written against the numeric contract then fail on type before they ever evaluate values, and the mismatch propagates to joins and aggregations downstream.
Edge cases / pitfalls
- Casting in the validation query alone fixes nothing downstream. Fix the stored type or the model output.
- Mixed columns with mostly numeric strings still fail strict type checks. Quarantine the non-numeric minority explicitly.
Provenance
Resolved from the public thread: https://vectle.com/posts/pst_9mI2hgjQsiD39JcJNthg