Skip to content

Conversation

@vojto
Copy link

@vojto vojto commented Dec 5, 2025

Hi, I started working on a PR to support structured objects in Anthropic: crmne/ruby_llm#528

It seems that Anthropic doesn't want strict: true in the schema, in fact, it blows up if it's present.

This small PR will only add struct: true if it's actually set to true, otherwise it'll omit the key.

We still set it to true by default, so in order to use schemas with Anthropic, one must explicitly set strict false or strict nil.

cc @danielfriis

@danielfriis
Copy link
Owner

danielfriis commented Dec 9, 2025

Thanks for the PR! Only skimmed through, but I'd prefer that strict is true and included by default so we don't break existing implementations.

@vojto
Copy link
Author

vojto commented Dec 9, 2025

@danielfriis that makes sense

So the problem is whenever you include strict in the schema, Anthropic will reject your request.

I rewrote it such that there's now a method to explicitly skip strict like this:

class MySchema < RubyLLM::Schema
  skip_strict true

  string :name, description: "The person's name"
end

This will make sure all existing schemas work the same way as before, but the library can also be used for providing schemas to Anthropic.

@danielfriis
Copy link
Owner

Hmmm. I see. So even if strict is set to false, Anthropic will reject it?

@vojto
Copy link
Author

vojto commented Dec 9, 2025

Hmmm. I see. So even if strict is set to false, Anthropic will reject it?

That's exactly right. It's like they don't support that field.

@danielfriis
Copy link
Owner

What if we allowed values true, false, and nil for the strict property and in case of nil, we don't include it?

class MySchema < RubyLLM::Schema
  strict nil

  string :name, description: "The person's name"
end

@vojto
Copy link
Author

vojto commented Dec 9, 2025

What if we allowed values true, false, and nil for the strict property and in case of nil, we don't include it?

That makes sense to me, but keep in mind it would slightly change the functionality:

CleanShot 2025-12-09 at 10 00 30@2x

If somebody is already doing strict nil, it's currently defaulting to true. So there's a very tiny chance of this being a breaking change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants