Skip to content

Fix schema mismatch in @effect/ai-anthropic citations field #5105

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed

Conversation

ethanzrd
Copy link

Automated Changes by SimulateDev

Setup

Task

Fix schema validation error in @effect/ai-anthropic package where citations field was incorrectly required but nullable, causing failures when Anthropic API omits the field entirely.

Coding agents used

  1. claude_code with Claude Opus 3 as Planner
  2. claude_code with Claude Opus 3 as Coder
  3. claude_code with Claude Opus 3 as Tester

Execution time

⏱️ 20m 47.0s


Summary

This PR resolves GitHub Issue #5079 by fixing a schema validation error in the @effect/ai-anthropic package. The issue occurred when the Anthropic API response omitted the citations field entirely, but our schema required it to be present (though nullable). The fix changes the schema definition from S.NullOr() to S.optionalWith({ nullable: true }), making the field truly optional while maintaining null value support. The solution includes an automated patch generation script for maintainability and has been thoroughly tested to ensure compatibility with the Anthropic API responses.

What changed?

  • Modified ResponseTextBlock and BetaResponseTextBlock schema definitions in ai-anthropic package
  • Changed citations field from S.NullOr() to S.optionalWith({ nullable: true })
  • Added automated patch generation script for schema updates
  • Included proper documentation with TODO comments referencing upstream issue
  • Comprehensive test coverage validating the schema fix

Review Instructions

Please carefully review all changes before merging. While AI agents are powerful, human oversight is always recommended.


Generated by SimulateDev, the AI coding agents collaboration platform.

- Change citations field from S.NullOr() to S.optionalWith({ nullable: true })
- Fix both ResponseTextBlock and BetaResponseTextBlock classes
- Addresses GitHub issue Effect-TS#5079 where schema validation failed
- Add automated patch generation script for maintainability

The previous implementation required the citations field to be present
but allowed null values. The Anthropic API may omit this field entirely,
causing validation failures. This change makes the field truly optional
while still allowing null values when present.
@ethanzrd ethanzrd requested a review from IMax153 as a code owner June 26, 2025 09:00
@github-project-automation github-project-automation bot moved this to Discussion Ongoing in PR Backlog Jun 26, 2025
Copy link

changeset-bot bot commented Jun 26, 2025

⚠️ No Changeset found

Latest commit: 9c71a89

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@IMax153
Copy link
Member

IMax153 commented Jul 1, 2025

Thank you @ethanzrd ! Sorry this PR languished for a bit.

This PR is now superceded by #5121, as that PR has several other similar fixes included.

@IMax153 IMax153 closed this Jul 1, 2025
@github-project-automation github-project-automation bot moved this from Discussion Ongoing to Done in PR Backlog Jul 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

2 participants