Skip to content

Exception using structured output in 1.16.0 #141

@tonydewan

Description

@tonydewan

Based on my reading of the API documentation, this should work:

params = {
  model: "claude-haiku-4-5",
  max_tokens: 1000,
  messages: [{role: "user", content: "respond with json"}],
  betas: ["structured-outputs-2025-11-13"],
  output_format: {
    type: "json_schema",
    schema: {
      "type" => "object",
      "properties" => {
        "test" => {"type" => "string"}
      },
      "required" => ["test"],
      "additionalProperties" => false
    }
  }
}

response = Anthropic::Client.new.messages.create(**params)
puts response.content[0].text

Worth noting that I also tried:

#...
response = Anthropic::Client.new.beta.messages.create(**params)
puts response.content[0].text

Either way, I get the following exception:

uninitialized constant Anthropic::Helpers::StructuredOutput (NameError)
in {output_format: {schema: Anthropic::Helpers::StructuredOutput::JsonSchemaConverter => model} => output_format}

Looks like the existence of schema in output_format results in a logical branch that references a nonexistent constant.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions