Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 1 addition & 32 deletions core/providers/anthropic/chat.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,38 +95,7 @@ func ToAnthropicChatRequest(ctx *schemas.BifrostContext, bifrostReq *schemas.Bif

// Convert function parameters to input_schema
if tool.Function.Parameters != nil && (tool.Function.Parameters.Type != "" || tool.Function.Parameters.Properties != nil) {
anthropicTool.InputSchema = &schemas.ToolFunctionParameters{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Pratham-Mishra04 I think this was to avoid altering original request right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point — the pointer is only read (serialized to JSON) after assignment so it's safe today, but a field-by-field copy is more defensive against future mutations. Happy to revert this if you'd prefer to keep the defensive copy. The main concern was that new fields added to ToolFunctionParameters would silently be dropped here without a corresponding update, but I understand the tradeoff.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes I think we directly serialize it after this so shouldnt be an issue but i'll confirm once

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you'd prefer to keep mutation safety, we could do a shallow struct copy instead:

params := *tool.Function.Parameters
anthropicTool.InputSchema = &params

This gives you the defensive copy (no shared pointer) while automatically forwarding any new fields added to ToolFunctionParameters — so no more silent field drops when the schema struct grows. Best of both worlds?

Type: tool.Function.Parameters.Type,
Description: tool.Function.Parameters.Description,
Properties: tool.Function.Parameters.Properties,
Required: tool.Function.Parameters.Required,
Enum: tool.Function.Parameters.Enum,
AdditionalProperties: tool.Function.Parameters.AdditionalProperties,
// JSON Schema definition fields
Defs: tool.Function.Parameters.Defs,
Definitions: tool.Function.Parameters.Definitions,
Ref: tool.Function.Parameters.Ref,
// Array schema fields
Items: tool.Function.Parameters.Items,
MinItems: tool.Function.Parameters.MinItems,
MaxItems: tool.Function.Parameters.MaxItems,
// Composition fields
AnyOf: tool.Function.Parameters.AnyOf,
OneOf: tool.Function.Parameters.OneOf,
AllOf: tool.Function.Parameters.AllOf,
// String validation fields
Format: tool.Function.Parameters.Format,
Pattern: tool.Function.Parameters.Pattern,
MinLength: tool.Function.Parameters.MinLength,
MaxLength: tool.Function.Parameters.MaxLength,
// Number validation fields
Minimum: tool.Function.Parameters.Minimum,
Maximum: tool.Function.Parameters.Maximum,
// Misc fields
Title: tool.Function.Parameters.Title,
Default: tool.Function.Parameters.Default,
Nullable: tool.Function.Parameters.Nullable,
}
anthropicTool.InputSchema = tool.Function.Parameters
}

if tool.CacheControl != nil {
Expand Down