Currently add_key_value() accepts any Python value and silently passes it
to struct.pack, which produces garbage when types are wrong (e.g. a list
passed where a string is expected). The failure only surfaces later as
an opaque struct.error during serialization, making bugs hard to diagnose.
This adds a _validate_value_type() classmethod that checks values against
the declared GGUFValueType before storing them, raising a clear TypeError
that includes the key name, expected type, actual type, and value.
Key design decisions:
- Reject bool for integer/float types (Python bool is int subclass)
- Accept int for float types (struct.pack handles this; conversion
scripts commonly pass integer literals like eps=0)
- Accept numpy scalar types (np.integer, np.floating, np.bool_)
- Allow bytes for ARRAY (used by add_array for UINT8 data like
precompiled_charsmap)
- Reject None for all types
Co-Authored-By: Claude <noreply@anthropic.com>