{"record":{"id":"5465fa550b5472fe","repo":"BoundaryML/baml","slug":"baml-fetch-as-expected-type-parameter-to-be-a-baml-type-got","errorCode":null,"errorMessage":"baml.fetch_as: expected type parameter to be a Baml type, got {}","messagePattern":"baml\\.fetch_as: expected type parameter to be a Baml type, got (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"engine/baml-runtime/src/async_vm_runtime.rs","lineNumber":568,"sourceCode":"\n                                BamlValue::Class(name, _) if name == \"baml.HttpRequest\" => {} // Ok,\n\n                                _ => {\n                                    break 'mainloop Err(anyhow!(\n                                        \"baml.fetch_as: expected baml.fetch_as arg to be a string or HttpRequest, got {}\",\n                                        url_or_request\n                                    ));\n                                }\n                            }\n\n                            let parse_as_type = match vm\n                                .objects\n                                .as_object(&pending_future.args[1], baml_vm::ObjectType::Any)\n                            {\n                                Ok(idx) => match &vm.objects[idx] {\n                                    baml_vm::Object::BamlType(type_ir) => type_ir.to_owned(),\n                                    _ => {\n                                        break 'mainloop Err(anyhow!(\n                                            \"baml.fetch_as: expected type parameter to be a Baml type, got {}\",\n                                            vm.objects[idx]\n                                        ));\n                                    }\n                                },\n                                Err(e) => {\n                                    break 'mainloop Err(anyhow::Error::from(e).context(\n                                        \"baml.fetch_as: failed to get type parameter from VM value\",\n                                    ));\n                                }\n                            };\n\n                            let future = {\n                                let futures_tx = futures_tx.clone();\n                                let cancel_tripwire = cancel_tripwire.to_owned();\n                                let current_call_id = current_call_id.to_owned();\n\n                                let output_format = jsonish::helpers::render_output_format(","sourceCodeStart":550,"sourceCodeEnd":586,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/baml-runtime/src/async_vm_runtime.rs#L550-L586","documentation":"The second argument of `baml.fetch_as` must be a BAML type (a BamlType IR object). The VM looked up the value and found a non-type object (a value instead of a type), so it cannot build an output format to parse the response.","triggerScenarios":"Passing an instance/value (string, class instance, map) instead of a type reference as the second argument, e.g. `baml.fetch_as(url, my_instance)` instead of `baml.fetch_as(url, MyType)`.","commonSituations":"Confusing a type with a value, passing a stringly-named type instead of the type identifier, or generated code emitting a value where a type parameter is required.","solutions":["Pass a BAML type identifier (e.g. `MyType`) as the second argument, not a value or string","Verify the type is declared in the .baml file and visible at the call site","If the type comes from a variable, ensure it was resolved to a type at compile time"],"exampleFix":"// before (BAML)\nlet data = baml.fetch_as(\"https://api.example.com/data\", \"MyType\")\n// after\nlet data = baml.fetch_as(\"https://api.example.com/data\", MyType)","handlingStrategy":"type-guard","validationCode":"// ensure the second argument is a type reference (capitalized identifier), not a value\nfunction isTypeReference(arg) {\n  return typeof arg === 'string' || typeof arg === 'object'\n    ? /^[A-Z][A-Za-z0-9_]*$/.test(String(arg))\n    : false;\n}","typeGuard":"function isBamlTypeRef(tok) { return typeof tok === 'string' && /^[A-Z][A-Za-z0-9_]*$/.test(tok); }","tryCatchPattern":"try {\n  const data = await runtime.callFunction(fnName, args);\n} catch (e) {\n  if (String(e).includes('expected type parameter to be a Baml type')) {\n    // replace args[1] with the type identifier (e.g. MyType) and retry\n  } else throw e;\n}","preventionTips":["Pass the type name itself, not an instance or quoted string of it","Confirm the type is declared in the .baml file"],"tags":["baml","type-mismatch","fetch","type-parameter"],"backgroundTag":"type-mismatch","analyzedSha":"bd85ce9dee1463ff04d27efd20531013a4ff46c1","analyzedAt":"2026-09-12T03:38:25.718Z","contentChangedAt":"2026-09-12T03:38:25.718Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}