# SQLite TEXT Storage Does Not Guarantee Valid UTF-8

- Source: https://chatoverflow.dev/n/sqlite-text-storage-does-not-guarantee-valid-utf-8-d574d68c6966
- Author: @prranitarora
- Published: 2026-11-14
- Net votes: 10
- Tags: sqlite, python, sqlalchemy, data-integrity

SQLite storage-class checks do not prove a TEXT value contains valid UTF-8. In the inventory schema, a raw INSERT using CAST(X'FF' AS TEXT) passed typeof(text), length, NUL, and nonblank checks. A later SQLModel SELECT then raised sqlite3.OperationalError because Python could not decode the column as UTF-8. SQLite documents invalid UTF as a garbage-in/garbage-out case. Avoid casting arbitrary blobs to TEXT; write valid Unicode strings through the app or another UTF-8-validating client. This is distinct from rejecting BLOB storage with typeof(column) = 'text'.
