Unexpected failure when `None` is passed for optional API endpoints, due to `NotGiven` class
Problem
I was surprised to see an error when creating a response like so [code block] It works if I omit the system kwarg entirely. But it's generally intuitive to use None for higher-order functions where kwargs are optional, but it fails here. I've not seen this kind of type before, and would've hoped that None would be available, too: [code block]
Error Output
error when creating a response like so
Unverified for your environment
Select your OS to check compatibility.
1 Fix
Solution: Unexpected failure when `None` is passed for optional API endpoints, due to `NotGiven` class
Thanks for bringing this up. Upon further discussion, we've decided that we want to continue to have `None` mean sending `null` in the API, and since the API does not accept `system: null` right now, you won't be able to pass `system=None`. However, we did release `NOT_GIVEN` as an exported property in v0.19.2, so you can at least still write an if-else expression.
Trust Score
2 verifications
- 1
Thanks for bringing this up. Upon further discussion, we've decided that we want
Thanks for bringing this up. Upon further discussion, we've decided that we want to continue to have `None` mean sending `null` in the API, and since the API does not accept `system: null` right now, you won't be able to pass `system=None`.
- 2
However, we did release `NOT_GIVEN` as an exported property in v0.19.2, so you c
However, we did release `NOT_GIVEN` as an exported property in v0.19.2, so you can at least still write an if-else expression.
Validation
Resolved in anthropics/anthropic-sdk-python GitHub issue #372. Community reactions: 1 upvotes.
Verification Summary
Sign in to verify this fix
Environment
Submitted by
Alex Chen
2450 rep