BoundaryML/baml · error
unexpected type for ID: %T
Error message
unexpected type for ID: %T
What it means
httpRequest.RequestId() expects the runtime 'id' method to return a Go string. 'unexpected type for ID: %T' means the bridge succeeded but returned a different Go type (e.g. nil, float64, map), so the value cannot be safely returned as a string.
Source
Thrown at engine/language_client_go/pkg/rawobjects_http_request.go:35
}
func (h *httpRequest) ObjectType() cffi.BamlObjectType {
return cffi.BamlObjectType_OBJECT_HTTP_REQUEST
}
func (h *httpRequest) pointer() int64 {
return h.RawObject.Pointer()
}
func (h *httpRequest) RequestId() (string, error) {
result, err := raw_objects.CallMethod(h, "id", nil)
if err != nil {
return "", fmt.Errorf("failed to get ID: %w", err)
}
id, ok := result.(string)
if !ok {
return "", fmt.Errorf("unexpected type for ID: %T", result)
}
return id, nil
}
func (h *httpRequest) Url() (string, error) {
result, err := raw_objects.CallMethod(h, "url", nil)
if err != nil {
return "", fmt.Errorf("failed to get URL: %w", err)
}
url, ok := result.(string)
if !ok {
return "", fmt.Errorf("unexpected type for URL: %T", result)
}
return url, nil
}View on GitHub (pinned to bd85ce9dee)
Solutions
- Fix the runtime/handler so 'id' returns a string
- Inspect %T in the message to see the actual returned type
- Add a conversion (e.g. fmt.Sprintf) only if the value is genuinely a non-string ID
- Verify client and runtime versions agree on the request shape
Example fix
// before
id, err := req.RequestId()
// after
id, err := req.RequestId()
if err != nil && strings.Contains(err.Error(), "unexpected type for ID: float64") {
log.Printf("runtime returned numeric ID; upgrade runtime or coerce")
} Defensive patterns
Strategy: try-catch
Validate before calling
// Cannot pre-validate; validate after call:
id, err := req.RequestId()
if err == nil && id == "" { /* runtime returned empty/non-string id */ } Type guard
func isString(v any) bool { _, ok := v.(string); return ok } Try / catch
id, err := req.RequestId()
if err != nil {
if strings.Contains(err.Error(), "unexpected type") {
return fmt.Errorf("runtime returned non-string ID: %w", err)
}
return err
} Prevention
- Ensure runtime 'id' implementations return plain strings
- Add contract tests asserting RequestId() returns a string
- Pin client/runtime versions together
When it happens
Trigger: The runtime's 'id' implementation returns a non-string (null, number, object) — e.g. a custom handler or script returning a numeric or absent ID.
Common situations: Custom request handlers/scripts that omit or redefine 'id'; schema changes in the runtime where IDs became numbers; serialization converting the ID type.
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
- unexpected type for logs: %T
- unexpected type in logs: %T
- unexpected type for last log: %T %v
- unexpected type for log by id: %T
- unexpected type for clear result: %T
AI-assisted analysis of BoundaryML/baml@bd85ce9dee (2026-09-12).
Data as JSON: /api/errors/78670e983beadbd6.
Report an issue: GitHub.