BoundaryML/baml · error · TypeError
failing inside parsed_using_types: {e:?}
Error message
failing inside parsed_using_types: {e:?} What it means
parsed_using_types converts a raw FunctionResult into typed Ruby objects using the provided types/partial_types TypeBuilders. When the internal parse (via the Rust core) fails, it wraps the debug-formatted error in a Ruby TypeError with this message.
Source
Thrown at engine/language_client_ruby/ext/ruby_ffi/src/function_result.rs:49
}
pub fn parsed_using_types(
ruby: &Ruby,
rb_self: &FunctionResult,
types: RModule,
partial_types: RModule,
allow_partials: bool,
) -> Result<Value> {
let res = match rb_self.inner.result_with_constraints_content() {
Ok(parsed) => ruby_to_json::RubyToJson::serialize_baml(
ruby,
types,
partial_types,
allow_partials,
parsed.clone(),
)
.map_err(|e| {
magnus::Error::new(
ruby.exception_type_error(),
format!("failing inside parsed_using_types: {e:?}"),
)
}),
Err(_) => Err(Error::new(
ruby.exception_runtime_error(),
format!("Failed to parse LLM response: {}", rb_self.inner),
)),
};
res
}
/// For usage in magnus::init
///
/// TODO: use traits and macros to implement this
pub fn define_in_ruby(module: &RModule) -> Result<()> {
let cls = module.define_class("FunctionResult", class::object())?;
View on GitHub (pinned to bd85ce9dee)
Solutions
- Print the embedded {e:?} detail — it names the actual validation failure
- Verify the TypeBuilder classes/aliases match the prompt's output schema
- Increase model reliability or improve the prompt's schema description
- For streams, tolerate partials and wait for done before strict parsing
Example fix
// before
parsed = result.parsed_using_types(types, partial_types, false)
// after
begin
parsed = result.parsed_using_types(types, partial_types, false)
rescue TypeError => e
warn "Parse failed: #{e.message}"
end Defensive patterns
Strategy: validation
Validate before calling
# ensure declared types match expected output schema before parsing
types.class_builder('Output').fields.each { |k, f| puts "#{k}: #{f.r#type}" } Try / catch
begin
parsed = result.parsed_using_types(types, partial_types, false)
rescue TypeError => e
logger.error("schema mismatch: #{e.message}")
end Prevention
- Keep the prompt's output schema and TypeBuilder in sync
- Test parsing against recorded LLM outputs
- Use allow_partials=true only for streaming contexts
When it happens
Trigger: Calling function.parsed_using_types (or result.parsed_using_types) with TypeBuilders where the LLM output does not match the declared types, allow_partials mismatch, or malformed types passed in.
Common situations: LLM returns JSON not conforming to the output class, wrong type names in the TypeBuilder, or streaming partial parse hitting an incomplete object that cannot be validated.
Understand the failure class
Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.
Related errors
- Failed to parse LLM response: {}
- baml.panics.HostContractViolation
- handle type mismatch
- Expected {expected}, got {actual}
- unsupported raw pointer type
AI-assisted analysis of BoundaryML/baml@bd85ce9dee (2026-09-12).
Data as JSON: /api/errors/088f15af7aea593f.
Report an issue: GitHub.