{"record":{"id":"1ca10c2f25961abb","repo":"huggingface/candle","slug":"expected-numeric-value-for-token-type-id-got-v","errorCode":null,"errorMessage":"expected numeric value for token type/id, got {v:?}","messagePattern":"expected numeric value for token type/id, got (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"candle-core/src/quantized/tokenizer.rs","lineNumber":41,"sourceCode":"\nfn metadata_value<'a>(ct: &'a gguf_file::Content, key: &str) -> Result<&'a gguf_file::Value> {\n    ct.metadata\n        .get(key)\n        .with_context(|| format!(\"missing GGUF metadata key `{key}`\"))\n}\n\nfn gguf_value_to_u32(v: &gguf_file::Value) -> Result<u32> {\n    use gguf_file::Value::*;\n    match v {\n        U8(v) => Ok(*v as u32),\n        I8(v) => Ok(*v as u32),\n        U16(v) => Ok(*v as u32),\n        I16(v) => Ok(*v as u32),\n        U32(v) => Ok(*v),\n        I32(v) => Ok(*v as u32),\n        U64(v) => Ok(*v as u32),\n        I64(v) => Ok(*v as u32),\n        _ => crate::bail!(\"expected numeric value for token type/id, got {v:?}\"),\n    }\n}\n\nfn value_to_string_array(v: &gguf_file::Value, name: &str) -> Result<Vec<String>> {\n    let arr = v\n        .to_vec()\n        .with_context(|| format!(\"`{name}` is not an array\"))?;\n    arr.iter()\n        .map(|v| {\n            v.to_string()\n                .map(|s| s.to_string())\n                .with_context(|| format!(\"`{name}` element is not a string: {v:?}\"))\n        })\n        .collect()\n}\n\nfn merges_from_value(v: &gguf_file::Value) -> Result<Vec<(String, String)>> {\n    value_to_string_array(v, \"tokenizer.ggml.merges\")?","sourceCodeStart":23,"sourceCodeEnd":59,"githubUrl":"https://github.com/huggingface/candle/blob/d5fee525bfde3273eb7c9b75fd2bc4937be867ca/candle-core/src/quantized/tokenizer.rs#L23-L59","documentation":"Thrown by gguf_value_to_u32 when a GGUF metadata field expected to be a numeric token type/id (e.g. tokenizer.ggml.token_type or added-token ids) holds a non-numeric value such as a string, bool, array or map. The helper only accepts U8/U16/U32/I16/I32/U64/I64 GGUF value variants.","triggerScenarios":"Loading a GGUF file whose tokenizer metadata contains a non-numeric value where a token type or token id is required, via Tokenizer::from_gguf / from_gguf converters calling gguf_value_to_u32.","commonSituations":"GGUF files produced by converters that wrote token_type as a string (e.g. \"1\") or stored ids in an array; hand-edited or malformed GGUF metadata; unsupported exporter versions.","solutions":["Re-export/regenerate the GGUF with a converter that writes numeric token types/ids (e.g. current llama.cpp convert script)","Inspect the GGUF metadata (gguf_file::Content) and fix the offending key to a numeric value","Bypass the strict conversion by reading the metadata yourself and passing values directly to Tokenizer::new"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"let v = ct.metadata.get(\"tokenizer.ggml.token_type\")\n    .ok_or_else(|| anyhow::anyhow!(\"missing token_type\"))?;\nif !matches!(v, GgmlDType-numeric(_) if true) { /* inspect: ensure it's a gguf_file::Value::U*/ }","typeGuard":"fn is_numeric_gguf_value(v: &gguf_file::Value) -> bool {\n    matches!(v,\n        gguf_file::Value::U8(_) | gguf_file::Value::U16(_) | gguf_file::Value::U32(_)\n        | gguf_file::Value::I16(_) | gguf_file::Value::I32(_)\n        | gguf_file::Value::U64(_) | gguf_file::Value::I64(_))\n}","tryCatchPattern":"match Tokenizer::from_gguf(&ct) {\n    Ok(t) => t,\n    Err(e) if e.to_string().contains(\"expected numeric value\") => {\n        return Err(anyhow::anyhow!(\"GGUF tokenizer metadata malformed; re-export the file: {e}\"))\n    }\n    Err(e) => return Err(e.into()),\n}","preventionTips":["Validate GGUF metadata types before loading (write a small pre-check over ct.metadata)","Use up-to-date llama.cpp converters that emit numeric token types","Sanity-check downloaded GGUF files against the model card/checksums"],"tags":["candle","gguf","tokenizer","metadata"],"backgroundTag":"gguf-metadata-invalid","analyzedSha":"d5fee525bfde3273eb7c9b75fd2bc4937be867ca","analyzedAt":"2026-09-02T00:15:47.023Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T06:17:21.866Z"}