BoundaryML/baml · error · SyntaxError
Invalid provider: {e:?}
Error message
Invalid provider: {e:?} What it means
A Ruby SyntaxError raised by ClientRegistry.add_llm_client when the provider string cannot be parsed into a ClientProvider via from_str. The parse error is debug-formatted into 'Invalid provider: {e:?}'. It means the provider name is not one BAML's registry recognizes.
Source
Thrown at engine/language_client_ruby/ext/ruby_ffi/src/types/client_registry.rs:41
pub fn add_llm_client(ruby: &Ruby, rb_self: &Self, args: &[Value]) -> Result<()> {
let args = scan_args::<_, _, (), (), (), ()>(args)?;
let (name, provider, options): (String, String, RHash) = args.required;
let (retry_policy,): (Option<String>,) = args.optional;
let options = match ruby_to_json::RubyToJson::convert_hash_to_json(options) {
Ok(options) => options,
Err(e) => {
return Err(Error::new(
ruby.exception_syntax_error(),
format!("error while parsing call_function args:\n{e}"),
));
}
};
let provider = match client_registry::ClientProvider::from_str(&provider) {
Ok(provider) => provider,
Err(e) => {
return Err(Error::new(
ruby.exception_syntax_error(),
format!("Invalid provider: {e:?}"),
));
}
};
let client_property =
client_registry::ClientProperty::new(name, provider, retry_policy, options);
rb_self.inner.borrow_mut().add_client(client_property);
Ok(())
}
pub fn set_primary(&self, primary: String) {
self.inner.borrow_mut().set_primary(primary);
}
pub fn define_in_ruby(module: &magnus::RModule) -> Result<()> {View on GitHub (pinned to bd85ce9dee)
Solutions
- Use an exact, lowercase provider name BAML knows: "openai", "anthropic", "aws", "google", "azure-openai", etc.
- Check the ClientProvider enum in your BAML version (baml-cli docs or generated Sorbet types) for valid values.
- Ensure you are passing the provider, not the model name — the model goes in options['model'].
- Trim whitespace/case-normalize the provider string built from config before calling.
- Upgrade the baml gem if the provider you need is newer than your installed version.
Example fix
// before
registry.add_llm_client("gpt", "GPT-4o", { "model" => "gpt-4o" })
// after
registry.add_llm_client("gpt", "openai", { "model" => "gpt-4o" }) Defensive patterns
Strategy: validation
Validate before calling
KNOWN_PROVIDERS = %w[openai anthropic aws google azure-openai]
raise "unknown provider #{provider}" unless KNOWN_PROVIDERS.include?(provider.strip.downcase) Try / catch
begin
registry.add_llm_client(name, provider, options)
rescue SyntaxError => e
raise ArgumentError, "bad provider #{provider.inspect}: #{e.message}" if e.message.start_with?('Invalid provider')
raise
end Prevention
- Keep a whitelist constant of valid provider strings and validate against it.
- Pass the provider name (lowercase), never the model name.
- Normalize provider strings: provider.to_s.strip.downcase.
- Regenerate client types after BAML upgrades in case provider enums changed.
When it happens
Trigger: Calling add_llm_client (or with_client overrides) with a provider string that isn't a known ClientProvider — e.g. "OpenAI" (wrong case), "openai-chat" (wrong variant), or a typo like "anthropicc".
Common situations: Using the human model name (e.g. "gpt-4o") instead of the provider name ("openai"); capitalization mismatches; switching providers after a BAML version change that renamed or added provider variants; dynamically built provider strings from config.
Understand the failure class
Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.
Related errors
- error while parsing LLM response for function {function_name
- error while parsing call_function args: {e}
- unknown feedback field(s) {}; only "title" and "description"
- feedback field "{key}" must be a string
- feedback needs a title; pass --title "..." or a JSON payload
AI-assisted analysis of BoundaryML/baml@bd85ce9dee (2026-09-12).
Data as JSON: /api/errors/fdc8b4dc2fee16cb.
Report an issue: GitHub.