Skip to content

Conversation

@waleedlatif1
Copy link
Collaborator

Summary

  • use anthropic sdk to transform malformed response schemas to anthropic format
  • anthropic adds additionalProperties: false to all response formats and has specific output criteria, so we use the official SDK to transform it

Type of Change

  • Bug fix

Testing

Tested manually

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

@vercel
Copy link

vercel bot commented Jan 25, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Review Updated (UTC)
docs Ready Ready Preview, Comment Jan 25, 2026 4:14am

Request Review

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Jan 25, 2026

Greptile Overview

Greptile Summary

Upgraded @anthropic-ai/sdk from 0.39.0 to 0.71.2 and replaced custom JSON schema transformation logic with the official SDK's built-in transformJSONSchema function.

Key Changes:

  • Upgraded SDK version from ^0.39.0 to 0.71.2 (exact version pinning)
  • Replaced manual schema transformation (previously ~170 lines in utils.ts) with SDK's transformJSONSchema import
  • Removed custom implementation that added additionalProperties: false and handled unsupported constraints
  • New SDK dependencies added: json-schema-to-ts@^3.1.1, ts-algebra@^2.0.0, @babel/runtime@7.28.6

Benefits:

  • Reduces maintenance burden by using official SDK implementation
  • Ensures compatibility with Anthropic's structured outputs API requirements
  • Eliminates risk of divergence from official transformation logic
  • Removes ~170 lines of custom code

Confidence Score: 5/5

  • Safe to merge - this change improves code quality by replacing custom logic with official SDK implementation
  • The PR correctly upgrades the Anthropic SDK and replaces a custom transformJSONSchema implementation with the official SDK's built-in function. The change is straightforward, well-isolated, and improves maintainability. The exact version pinning (0.71.2 instead of ^0.71.2) ensures consistency. Previous version conflicts mentioned in earlier review threads have been properly resolved - the old 0.39.0 version only remains as a dependency of @browserbasehq/stagehand, which won't conflict with the sim app's usage.
  • No files require special attention

Important Files Changed

Filename Overview
apps/sim/package.json Upgraded @anthropic-ai/sdk from ^0.39.0 to 0.71.2 with exact version pinning
apps/sim/providers/anthropic/index.ts Replaced manual schema transformation with official SDK's transformJSONSchema function from @anthropic-ai/sdk/lib/transform-json-schema
bun.lock Updated lockfile reflects SDK upgrade to 0.71.2 with new dependencies (json-schema-to-ts, ts-algebra, @babel/runtime)

Sequence Diagram

sequenceDiagram
    participant Client
    participant AnthropicProvider
    participant SDK as @anthropic-ai/sdk
    participant Transform as transformJSONSchema
    participant API as Anthropic API

    Client->>AnthropicProvider: executeRequest(request)
    
    alt request.responseFormat exists
        AnthropicProvider->>AnthropicProvider: Check if native structured outputs supported
        
        alt useNativeStructuredOutputs = true
            Note over AnthropicProvider: Extract schema from request.responseFormat
            AnthropicProvider->>Transform: transformJSONSchema(schema)
            Note over Transform: SDK transforms schema:<br/>- Adds additionalProperties: false<br/>- Removes unsupported constraints<br/>- Filters string formats
            Transform-->>AnthropicProvider: transformedSchema
            AnthropicProvider->>AnthropicProvider: Set payload.output_format = {<br/>  type: 'json_schema',<br/>  schema: transformedSchema<br/>}
        else useNativeStructuredOutputs = false
            AnthropicProvider->>AnthropicProvider: generateSchemaInstructions(schema)
            AnthropicProvider->>AnthropicProvider: Append schema to system prompt
        end
    end
    
    AnthropicProvider->>SDK: messages.create(payload)
    SDK->>API: HTTP Request with transformed schema
    API-->>SDK: Response
    SDK-->>AnthropicProvider: Response
    AnthropicProvider-->>Client: ProviderResponse | StreamingExecution
Loading

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

2 files reviewed, 2 comments

Edit Code Review Agent Settings | Greptile

@waleedlatif1
Copy link
Collaborator Author

@greptile

Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 2 potential issues.

Bugbot Autofix is OFF. To automatically fix reported issues with Cloud Agents, enable Autofix in the Cursor dashboard.

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

2 files reviewed, 2 comments

Edit Code Review Agent Settings | Greptile

@waleedlatif1
Copy link
Collaborator Author

@greptile

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

No files reviewed, no comments

Edit Code Review Agent Settings | Greptile

@waleedlatif1 waleedlatif1 merged commit ac91d78 into staging Jan 25, 2026
11 checks passed
@waleedlatif1 waleedlatif1 deleted the fix/resp branch January 25, 2026 04:31
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