Skip to content
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

correctly raise ValueError for ChatBedrock models that don't support structured_output #126

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions libs/aws/langchain_aws/chat_models/bedrock.py
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ class ChatBedrock(BaseChatModel, BedrockBase):

system_prompt_with_tools: str = ""
beta_use_converse_api: bool = False
"""Use the new Bedrock ``converse`` API which provides a standardized interface to
"""Use the new Bedrock ``converse`` API which provides a standardized interface to
all Bedrock models. Support still in beta. See ChatBedrockConverse docs for more."""

@property
Expand Down Expand Up @@ -784,7 +784,7 @@ class AnswerWithJustification(BaseModel):
schema, include_raw=include_raw, **kwargs
)
if "claude-3" not in self._get_model():
ValueError(
raise ValueError(
f"Structured output is not supported for model {self._get_model()}"
)
Comment on lines 786 to 789
Copy link
Collaborator

Choose a reason for hiding this comment

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

I would suggest to rather get rid of this block as there are other providers that support tool calling and structured output.

Copy link
Author

Choose a reason for hiding this comment

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

is there an up-to-date list of these providers given by AWS? the above branch condition was written by the original PR author. I think it's correct as from my manual testing, only claude-3 models support structured output on Bedrock (for now).
I'm only providing a code correction so it correctly raises an error like it should have been doing, not any major breaking changes.


Expand Down
10 changes: 10 additions & 0 deletions libs/aws/tests/integration_tests/chat_models/test_bedrock.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,16 @@ def test_structured_output() -> None:
assert isinstance(response, AnswerWithJustification)


@pytest.mark.scheduled
def test_unsupported_structured_output() -> None:
chat = ChatBedrock(
model_id="meta.llama3-8b-instruct-v1:0",
model_kwargs={"temperature": 0.001},
) # type: ignore[call-arg]
with pytest.raises(ValueError):
_ = chat.with_structured_output(AnswerWithJustification)


@pytest.mark.scheduled
def test_tool_use_call_invoke() -> None:
chat = ChatBedrock(
Expand Down