-
Notifications
You must be signed in to change notification settings - Fork 396
Description
Just ran into this slight inconsistency in the API relating to structured content support.
Here's the messages.create() idea of output_format=:
| output_format: Optional[BetaJSONOutputFormatParam] | Omit = omit, |
Which uses:
anthropic-sdk-python/src/anthropic/types/beta/beta_json_output_format_param.py
Lines 11 to 15 in d9aea38
| class BetaJSONOutputFormatParam(TypedDict, total=False): | |
| schema: Required[Dict[str, object]] | |
| """The JSON schema of the format""" | |
| type: Required[Literal["json_schema"]] |
So it accepts a Python dictionary that represents a JSON schema.
But the messages.stream() method:
| output_format: Optional[type[ResponseFormatT]] | Omit = omit, |
Later does this:
anthropic-sdk-python/src/anthropic/resources/beta/messages/messages.py
Lines 1385 to 1386 in d9aea38
| if is_given(output_format) and output_format is not None: | |
| adapted_type: TypeAdapter[ResponseFormatT] = TypeAdapter(output_format) |
TypeAdapter is a Pydantic concept, so this has the effect of only allowing Pydantic types to be passed to messages.stream().
It's confusing and inconsistent that messages.create() requires a JSON schema dictionary but messages.stream() instead requires a Pydantic model.