{"record":{"id":"b343c1ea1e314790","repo":"BoundaryML/baml","slug":"text-is-not-a-string","errorCode":null,"errorMessage":"text is not a string","messagePattern":"text is not a string","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"engine/language_client_cffi/src/ffi/functions.rs","lineNumber":169,"sourceCode":"        }\n    };\n\n    // Convert keyword arguments.\n    let BamlFunctionArguments {\n        kwargs,\n        client_registry,\n        env_vars,\n        collectors: _,\n        type_builder,\n        tags: _,\n    } = BamlFunctionArguments::from_c_buffer(encoded_args, length)?;\n\n    let ctx = runtime.create_ctx_manager(BamlValue::String(\"cffi\".to_string()), None);\n    let text = match kwargs.get(\"text\") {\n        Some(t) => match t.as_str() {\n            Some(s) => s.to_string(),\n            None => {\n                return Err(anyhow::anyhow!(\"text is not a string\"));\n            }\n        },\n        None => {\n            return Err(anyhow::anyhow!(\"text is required\"));\n        }\n    };\n    let allow_stream_types = match kwargs.get(\"stream\") {\n        Some(s) => match s.as_bool() {\n            Some(b) => b,\n            None => {\n                return Err(anyhow::anyhow!(\"stream is not a boolean\"));\n            }\n        },\n        None => false,\n    };\n\n    // Spawn an async task to await the future and call the callback when done.\n    // Ensure that a Tokio runtime is running in your application.","sourceCodeStart":151,"sourceCodeEnd":187,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/language_client_cffi/src/ffi/functions.rs#L151-L187","documentation":"call_function_parse_from_c requires a keyword argument named \"text\" that must be a BAML string value, because it invokes the special parse operation on raw text. If \"text\" is present but is not a string (e.g. an int, bool, or object), the library raises this error instead of coercing.","triggerScenarios":"Calling the parse FFI entry point with kwargs containing text as a non-string BamlValue (int, list, bool, etc.).","commonSituations":"Passing user input or parsed data directly as text without str() conversion; mixing up the parse API's argument contract with generic function calls.","solutions":["Coerce the value to a string before calling parse (str(text) / String(text))","Verify you are using the parse API correctly — it expects the raw LLM output string","Log the type of the value passed as text to confirm what the host actually sends"],"exampleFix":"// before\nbaml.baml_call_function_parse(rt, \"fn\", {\"text\": 12345})\n// after\nbaml.baml_call_function_parse(rt, \"fn\", {\"text\": str(llm_output)})","handlingStrategy":"type-guard","validationCode":"if not isinstance(text, str):\n    raise TypeError(f\"text must be str, got {type(text)}\")","typeGuard":"def is_str(v): return isinstance(v, str)","tryCatchPattern":"try:\n    parsed = baml.baml_call_function_parse(rt, fn, {\"text\": text})\nexcept Exception as e:\n    if 'text is not a string' in str(e):\n        parsed = baml.baml_call_function_parse(rt, fn, {\"text\": str(text)})\n    else:\n        raise","preventionTips":["Coerce LLM output to str before parsing","Check types when passing values from JSON/config","Log value types when debugging parse calls"],"tags":["ffi","rust","type-mismatch","parse"],"backgroundTag":"type-mismatch","analyzedSha":"bd85ce9dee1463ff04d27efd20531013a4ff46c1","analyzedAt":"2026-09-12T03:38:25.718Z","contentChangedAt":"2026-09-12T03:38:25.718Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}