BoundaryML/baml · error
baml.fetch_as: expected url to be a string, got {}
Error message
baml.fetch_as: expected url to be a string, got {} What it means
When `baml.fetch_as` receives a baml.HttpRequest class, it reads the `url` field and expects it to be a string. The field was missing or held a non-string value, so the HTTP request cannot be built. (The message prints the whole request object, not the offending field.)
Source
Thrown at engine/baml-runtime/src/async_vm_runtime.rs:606
&parse_as_type,
&baml_types::EvaluationContext::default(),
baml_types::StreamingMode::NonStreaming,
)
.unwrap();
async move {
let response = 'res: {
let client = reqwest::Client::new();
let req = match &url_or_request {
BamlValue::String(url) => {
client.get(url)
}
// we type checked earlier, should be http request type
BamlValue::Class(name, fields) => {
let Some(BamlValue::String(url)) = fields.get("url") else {
break 'res Err(anyhow!(
"baml.fetch_as: expected url to be a string, got {}",
url_or_request
));
};
let Some(BamlValue::Enum(_, method)) = fields.get("method") else {
break 'res Err(anyhow!(
"baml.fetch_as: expected method to be a valid HTTP method, got {}",
url_or_request
));
};
let mut req = match method.as_str() {
"Get" => client.get(url),
"Post" => client.post(url),
"Put" => client.put(url),
"Patch" => client.patch(url),
"Delete" => client.delete(url),View on GitHub (pinned to bd85ce9dee)
Solutions
- Add a `url` string field to the baml.HttpRequest constructor
- Ensure the url variable is a string (coerce/interpolate it) before building the request
- Fix field-name typos (`url` exactly, not `uri` or `endpoint`)
Example fix
// before (BAML)
let req = baml.HttpRequest{method: "Get", url: null}
// after
let req = baml.HttpRequest{method: "Get", url: "https://api.example.com/data"} Defensive patterns
Strategy: validation
Validate before calling
function validateHttpRequest(req) {
if (!req || typeof req !== 'object') throw new Error('HttpRequest required');
if (typeof req.url !== 'string' || req.url.length === 0) throw new Error('HttpRequest.url must be a non-empty string, got: ' + JSON.stringify(req.url));
} Type guard
function hasStringUrl(req) {
return typeof req === 'object' && req !== null && typeof req.url === 'string' && req.url.length > 0;
} Try / catch
try {
const data = await runtime.callFunction(fnName, args);
} catch (e) {
if (String(e).includes('expected url to be a string')) {
// inspect the baml.HttpRequest construction site and fix the url field
} else throw e;
} Prevention
- Always set `url` explicitly as a string on baml.HttpRequest
- Check for null/undefined url variables at construction time
- Use the field name `url`, not `uri` or `endpoint`
When it happens
Trigger: Constructing baml.HttpRequest without a `url` field, or with a url that is not a string (e.g. an int, null, or a nested object).
Common situations: Typos like `uri:` instead of `url:`, building the request dynamically where the url variable is null/undefined at runtime, or deserializing a request from JSON that lacks the url field.
Understand the failure class
Background: Type mismatch errors: IllegalArgumentException, TypeError and type guards across 150 open-source libraries — this error's family across 150 libraries.
Related errors
- baml.fetch_as: expected method to be a valid HTTP method, go
- baml.fetch_as: expected header value to be a string, got {}
- type `{ty}` can't be passed through auto-CLI; deliver it via
- baml.json.deserialize failed: {e:?}
- baml.json.serialize returned non-string value: {other:?}
AI-assisted analysis of BoundaryML/baml@bd85ce9dee (2026-09-12).
Data as JSON: /api/errors/c6944e0111a5786a.
Report an issue: GitHub.