Repository navigation
fix: be lenient for anthropic parsing - #157
Conversation
WalkthroughThe PR modifies the Anthropic translator to tolerate unknown or experimental request fields instead of rejecting them. The JSON decoder now permits unlisted fields, security tests confirm tolerance behaviour and validate error boundaries, and documentation describes the new handling for users. ChangesLenient Anthropic Request Fields
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Suggested labels
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@internal/adapter/translator/anthropic/security_test.go`:
- Around line 414-415: The failing assertion is too broad (assert.Contains(t,
err.Error(), "invalid request")); tighten it to assert the specific validation
failure for the temperature parameter by checking the error text contains the
temperature validation path or message (e.g., include "temperature" or the full
validation phrase emitted by Validate()) so replace the broad check with an
assertion like assert.Contains(t, err.Error(), "temperature") or
assert.Contains(t, err.Error(), "request.temperature") to ensure the test fails
only when temperature bounds regress; refer to the local error variable err and
the Validate() temperature check in this test to locate where to update the
assertion.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 99c435fe-6dc3-426d-aa36-08b76db85490
📒 Files selected for processing (4)
docs/content/integrations/api-translation/anthropic.mdinternal/adapter/translator/anthropic/extended_features_test.gointernal/adapter/translator/anthropic/request.gointernal/adapter/translator/anthropic/security_test.go
| // Unknown field is silently ignored; rejection comes from Validate() on temperature. | ||
| assert.Contains(t, err.Error(), "invalid request") |
There was a problem hiding this comment.
Tighten the failure assertion to the actual invalid parameter path.
Line 415 only asserting "invalid request" is too broad and can mask regressions unrelated to temperature bounds. Assert the specific validation reason as well.
Suggested test assertion tightening
- assert.Contains(t, err.Error(), "invalid request")
+ assert.Contains(t, err.Error(), "invalid request")
+ assert.Contains(t, err.Error(), "temperature must be between 0 and 2")📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| // Unknown field is silently ignored; rejection comes from Validate() on temperature. | |
| assert.Contains(t, err.Error(), "invalid request") | |
| // Unknown field is silently ignored; rejection comes from Validate() on temperature. | |
| assert.Contains(t, err.Error(), "invalid request") | |
| assert.Contains(t, err.Error(), "temperature must be between 0 and 2") |
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@internal/adapter/translator/anthropic/security_test.go` around lines 414 -
415, The failing assertion is too broad (assert.Contains(t, err.Error(),
"invalid request")); tighten it to assert the specific validation failure for
the temperature parameter by checking the error text contains the temperature
validation path or message (e.g., include "temperature" or the full validation
phrase emitted by Validate()) so replace the broad check with an assertion like
assert.Contains(t, err.Error(), "temperature") or assert.Contains(t,
err.Error(), "request.temperature") to ensure the test fails only when
temperature bounds regress; refer to the local error variable err and the
Validate() temperature check in this test to locate where to update the
assertion.
Addresses #154 and how newer fields cause issues for the Anthropic transformer.
This PR makes it more lenient and accepting of unknown fields in the Anthropic Translator and proxy.
Summary by CodeRabbit
Release Notes
Improvements
Tests