huggingface/candle · error
not a bool {v:?}
Error message
not a bool {v:?} What it means
Value::to_bool throws this when the GGUF metadata value is not the Bool variant. GGUF booleans are a distinct tagged type; candle will not interpret e.g. a u8 or string as a boolean. The offending value is printed with Debug formatting in the message.
Source
Thrown at candle-core/src/quantized/gguf_file.rs:301
pub fn to_f32(&self) -> Result<f32> {
match self {
Self::F32(v) => Ok(*v),
v => crate::bail!("not a f32 {v:?}"),
}
}
pub fn to_f64(&self) -> Result<f64> {
match self {
Self::F64(v) => Ok(*v),
v => crate::bail!("not a f64 {v:?}"),
}
}
pub fn to_bool(&self) -> Result<bool> {
match self {
Self::Bool(v) => Ok(*v),
v => crate::bail!("not a bool {v:?}"),
}
}
pub fn to_vec(&self) -> Result<&Vec<Value>> {
match self {
Self::Array(v) => Ok(v),
v => crate::bail!("not a vec {v:?}"),
}
}
pub fn to_string(&self) -> Result<&String> {
match self {
Self::String(v) => Ok(v),
v => crate::bail!("not a string {v:?}"),
}
}
fn read<R: std::io::Read + std::io::Seek>(View on GitHub (pinned to d5fee525bf)
Solutions
- Check the error's {v:?} and use the correct accessor — for a u8 flag, test .to_u8() != 0.
- Match on the Value enum and treat Value::U8(1)/Value::Bool(true) as true.
- Fix the GGUF writer to emit ValueType::Bool for this field.
- Reject the file during pre-validation if a required field must be a strict bool.
Example fix
// before
let add_bos = value.to_bool()?;
// after
let add_bos = match value {
gguf_file::Value::Bool(b) => b,
gguf_file::Value::U8(b) => b != 0,
other => candle_core::bail!("unexpected add_bos flag {other:?}"),
}; Defensive patterns
Strategy: type-guard
Validate before calling
fn is_bool(v: &gguf_file::Value) -> bool { matches!(v, gguf_file::Value::Bool(_)) }
if !is_bool(value) { bail!("expected bool metadata, got {value:?}"); } Type guard
fn as_bool(v: &gguf_file::Value) -> Option<bool> {
match v {
gguf_file::Value::Bool(b) => Some(*b),
gguf_file::Value::U8(b) => Some(*b != 0),
_ => None,
}
} Try / catch
let b = match value {
gguf_file::Value::Bool(b) => b,
other => { eprintln!("flag not bool: {other:?}"); false }
}; Prevention
- Treat u8 flags as potential bools when reading files from varied producers
- Inspect Value::value_type() before choosing an accessor
- Keep a schema of expected key->type for the architectures you support
- Reject files whose required flag fields are not the expected type
When it happens
Trigger: Calling .to_bool() on a metadata entry stored as U8 (some GGUF writers encode flags as u8 0/1), or on any String/Array entry, e.g. a 'tokenizer.ggml.add_bos_token' flag written as u8.
Common situations: Reading GGUF files produced by writers that predate or ignore the bool value type and use u8 flags; assuming custom metadata fields are bools without checking the type; copy-pasted accessor code from another field.
Related errors
- not a f32 {v:?}
- not a f64 {v:?}
- not a vec {v:?}
- not a string {v:?}
- multiple value-types in the same array {value_type:?}
AI-assisted analysis of huggingface/candle@d5fee525bf (2026-09-02).
Data as JSON: /api/errors/dd4ef2dfe8eeeffc.
Report an issue: GitHub.