Skip to content

fix(aws): Raise error on unsupported guardrail header usage with Mantle - #1225

Merged
Michael Chin (michaelnchin) merged 2 commits into
langchain-ai:mainfrom
michaelnchin:fix/mantle-guardrails-validation
Aug 25, 2026
Merged

fix(aws): Raise error on unsupported guardrail header usage with Mantle#1225
Michael Chin (michaelnchin) merged 2 commits into
langchain-ai:mainfrom
michaelnchin:fix/mantle-guardrails-validation

Conversation

@michaelnchin

@michaelnchin Michael Chin (michaelnchin) commented Aug 22, 2026

Copy link
Copy Markdown
Collaborator

Fixes #1224:

Updates AnthropicBedrockMantle and ChatOpenAIMantle to catch and throw an error on user attempts to pass X-Amzn-Bedrock-Guardrail* headers, which are currently unsupported on Mantle endpoint.

Marked TODO removal, as this is expected to be a temporary mitigation until Mantle guardrails support is added.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Integ CI failing, due to unrelated error on Mistral standard tests - fix pending here: #1228

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

@michaelnchin
Michael Chin (michaelnchin) merged commit 6ae3f6e into langchain-ai:main Aug 25, 2026
15 checks passed
@michaelnchin
Michael Chin (michaelnchin) deleted the fix/mantle-guardrails-validation branch August 25, 2026 00:54
Rishabh Agrawal (rishabhagrawal1) added a commit to rishabhagrawal1/langchain-aws that referenced this pull request Sep 1, 2026
Add ChatOpenAIBedrock, targeting the OpenAI-compatible Chat Completions
and Responses APIs on the bedrock-runtime endpoint
(bedrock-runtime.{region}.amazonaws.com/openai/v1). This is the
recommended endpoint for OpenAI models (e.g. GPT-5.x) on Amazon Bedrock
and supports cross-Region inference via geographic/global inference
profile ids passed as the model
(https://docs.aws.amazon.com/bedrock/latest/userguide/endpoints.html).

Refactor the shared logic out of ChatOpenAIMantle into a private
_BaseChatBedrockOpenAI base so both endpoints share region/base-URL
resolution, Bedrock API-key auth (static bearer token or short-term keys
derived from AWS credentials, following langchain-ai#1203), profile resolution,
LangSmith tracing metadata, and the Chat Completions/Responses routing.
Each public class only sets endpoint-specific class attributes;
ChatOpenAIMantle's public surface is unchanged. The base rejects direct
instantiation with a clear error.

Extract the shared cross-Region prefix stripping and guardrail-rejection
guard into langchain_aws.utils helpers, and route ChatBedrockConverse and
ChatAnthropicMantle through them, removing the duplicated copies (the
guard was previously duplicated per langchain-ai#1225). Behavior is unchanged.

Resolve capability profiles through any cross-Region prefix, so a
geographic id such as us.openai.gpt-5.6-sol reuses the base
openai.gpt-5.6-sol capability profile (mirroring ChatBedrockConverse).

Guardrails are rejected on the OpenAI-compatible path for both endpoints:
bedrock-mantle silently ignores them, and no OpenAI model on
bedrock-runtime accepts them yet.
Rishabh Agrawal (rishabhagrawal1) added a commit to rishabhagrawal1/langchain-aws that referenced this pull request Sep 1, 2026
Add ChatOpenAIBedrock, targeting the OpenAI-compatible Chat Completions
and Responses APIs on the bedrock-runtime endpoint
(bedrock-runtime.{region}.amazonaws.com/openai/v1). This is the
recommended endpoint for OpenAI models (e.g. GPT-5.x) on Amazon Bedrock
and supports cross-Region inference via geographic/global inference
profile ids passed as the model
(https://docs.aws.amazon.com/bedrock/latest/userguide/endpoints.html).

Refactor the shared logic out of ChatOpenAIMantle into a private
_BaseChatBedrockOpenAI base so both endpoints share region/base-URL
resolution, Bedrock API-key auth (static bearer token or short-term keys
derived from AWS credentials, following langchain-ai#1203), profile resolution,
LangSmith tracing metadata, and the Chat Completions/Responses routing.
Each public class only sets endpoint-specific class attributes;
ChatOpenAIMantle's public surface is unchanged. The base rejects direct
instantiation with a clear error.

Extract the shared cross-Region prefix stripping and guardrail-rejection
guard into langchain_aws.utils helpers, and route ChatBedrockConverse and
ChatAnthropicMantle through them, removing the duplicated copies (the
guard was previously duplicated per langchain-ai#1225). Behavior is unchanged.

Resolve capability profiles through any cross-Region prefix, so a
geographic id such as us.openai.gpt-5.6-sol reuses the base
openai.gpt-5.6-sol capability profile (mirroring ChatBedrockConverse).

Guardrails are rejected on the OpenAI-compatible path for both endpoints:
bedrock-mantle silently ignores them, and no OpenAI model on
bedrock-runtime accepts them yet.
Rishabh Agrawal (rishabhagrawal1) added a commit to rishabhagrawal1/langchain-aws that referenced this pull request Sep 1, 2026
Add ChatOpenAIBedrock, targeting the OpenAI-compatible Chat Completions
and Responses APIs on the bedrock-runtime endpoint
(bedrock-runtime.{region}.amazonaws.com/openai/v1). This is the
recommended endpoint for OpenAI models (e.g. GPT-5.x) on Amazon Bedrock
and supports cross-Region inference via geographic/global inference
profile ids passed as the model
(https://docs.aws.amazon.com/bedrock/latest/userguide/endpoints.html).

Refactor the shared logic out of ChatOpenAIMantle into a private
_BaseChatBedrockOpenAI base so both endpoints share region/base-URL
resolution, Bedrock API-key auth (static bearer token or short-term keys
derived from AWS credentials, following langchain-ai#1203), profile resolution,
LangSmith tracing metadata, and the Chat Completions/Responses routing.
Each public class only sets endpoint-specific class attributes;
ChatOpenAIMantle's public surface is unchanged. The base rejects direct
instantiation with a clear error.

Extract the shared cross-Region prefix stripping and guardrail-rejection
guard into langchain_aws.utils helpers, and route ChatBedrockConverse and
ChatAnthropicMantle through them, removing the duplicated copies (the
guard was previously duplicated per langchain-ai#1225). Behavior is unchanged.

Resolve capability profiles through any cross-Region prefix, so a
geographic id such as us.openai.gpt-5.6-sol reuses the base
openai.gpt-5.6-sol capability profile (mirroring ChatBedrockConverse).

Guardrails are rejected on the OpenAI-compatible path for both endpoints:
bedrock-mantle silently ignores them, and no OpenAI model on
bedrock-runtime accepts them yet.
Rishabh Agrawal (rishabhagrawal1) added a commit to rishabhagrawal1/langchain-aws that referenced this pull request Sep 1, 2026
Add ChatOpenAIBedrock, targeting the OpenAI-compatible Chat Completions
and Responses APIs on the bedrock-runtime endpoint
(bedrock-runtime.{region}.amazonaws.com/openai/v1). This is the
recommended endpoint for OpenAI models (e.g. GPT-5.x) on Amazon Bedrock
and supports cross-Region inference via geographic/global inference
profile ids passed as the model
(https://docs.aws.amazon.com/bedrock/latest/userguide/endpoints.html).

Refactor the shared logic out of ChatOpenAIMantle into a private
_BaseChatBedrockOpenAI base so both endpoints share region/base-URL
resolution, Bedrock API-key auth (static bearer token or short-term keys
derived from AWS credentials, following langchain-ai#1203), profile resolution,
LangSmith tracing metadata, and the Chat Completions/Responses routing.
Each public class only sets endpoint-specific class attributes;
ChatOpenAIMantle's public surface is unchanged. The base rejects direct
instantiation with a clear error.

Extract the shared cross-Region prefix stripping and guardrail-rejection
guard into langchain_aws.utils helpers, and route ChatBedrockConverse and
ChatAnthropicMantle through them, removing the duplicated copies (the
guard was previously duplicated per langchain-ai#1225). Behavior is unchanged.

Resolve capability profiles through any cross-Region prefix, so a
geographic id such as us.openai.gpt-5.6-sol reuses the base
openai.gpt-5.6-sol capability profile (mirroring ChatBedrockConverse).

Guardrails are rejected on the OpenAI-compatible path for both endpoints:
bedrock-mantle silently ignores them, and no OpenAI model on
bedrock-runtime accepts them yet.
Rishabh Agrawal (rishabhagrawal1) added a commit to rishabhagrawal1/langchain-aws that referenced this pull request Sep 1, 2026
Add ChatOpenAIBedrock, targeting the OpenAI-compatible Chat Completions
and Responses APIs on the bedrock-runtime endpoint
(bedrock-runtime.{region}.amazonaws.com/openai/v1). This is the
recommended endpoint for OpenAI models (e.g. GPT-5.x) on Amazon Bedrock
and supports cross-Region inference via geographic/global inference
profile ids passed as the model
(https://docs.aws.amazon.com/bedrock/latest/userguide/endpoints.html).

Refactor the shared logic out of ChatOpenAIMantle into a private
_BaseChatBedrockOpenAI base so both endpoints share region/base-URL
resolution, Bedrock API-key auth (static bearer token or short-term keys
derived from AWS credentials, following langchain-ai#1203), profile resolution,
LangSmith tracing metadata, and the Chat Completions/Responses routing.
Each public class only sets endpoint-specific class attributes;
ChatOpenAIMantle's public surface is unchanged. The base rejects direct
instantiation with a clear error.

Extract the shared cross-Region prefix stripping and guardrail-rejection
guard into langchain_aws.utils helpers, and route ChatBedrockConverse and
ChatAnthropicMantle through them, removing the duplicated copies (the
guard was previously duplicated per langchain-ai#1225). Behavior is unchanged.

Resolve capability profiles through any cross-Region prefix, so a
geographic id such as us.openai.gpt-5.6-sol reuses the base
openai.gpt-5.6-sol capability profile (mirroring ChatBedrockConverse).

Guardrails are rejected on the OpenAI-compatible path for both endpoints:
bedrock-mantle silently ignores them, and no OpenAI model on
bedrock-runtime accepts them yet.
Rishabh Agrawal (rishabhagrawal1) added a commit to rishabhagrawal1/langchain-aws that referenced this pull request Sep 1, 2026
Add ChatOpenAIBedrock, targeting the OpenAI-compatible Chat Completions
and Responses APIs on the bedrock-runtime endpoint
(bedrock-runtime.{region}.amazonaws.com/openai/v1). This is the
recommended endpoint for OpenAI models (e.g. GPT-5.x) on Amazon Bedrock
and supports cross-Region inference via geographic/global inference
profile ids passed as the model
(https://docs.aws.amazon.com/bedrock/latest/userguide/endpoints.html).

Refactor the shared logic out of ChatOpenAIMantle into a private
_BaseChatBedrockOpenAI base so both endpoints share region/base-URL
resolution, Bedrock API-key auth (static bearer token or short-term keys
derived from AWS credentials, following langchain-ai#1203), profile resolution,
LangSmith tracing metadata, and the Chat Completions/Responses routing.
Each public class only sets endpoint-specific class attributes;
ChatOpenAIMantle's public surface is unchanged. The base rejects direct
instantiation with a clear error.

Extract the shared cross-Region prefix stripping and guardrail-rejection
guard into langchain_aws.utils helpers, and route ChatBedrockConverse and
ChatAnthropicMantle through them, removing the duplicated copies (the
guard was previously duplicated per langchain-ai#1225). Behavior is unchanged.

Resolve capability profiles through any cross-Region prefix, so a
geographic id such as us.openai.gpt-5.6-sol reuses the base
openai.gpt-5.6-sol capability profile (mirroring ChatBedrockConverse).

Guardrails are rejected on the OpenAI-compatible path for both endpoints:
bedrock-mantle silently ignores them, and no OpenAI model on
bedrock-runtime accepts them yet.
roi hezkiyahu (roihezkiRaven) added a commit to roihezkiRaven/langchain-aws that referenced this pull request Sep 2, 2026
The built client signs with SigV4 only, so a configured `bedrock_api_key`
would have been silently ignored and the request authenticated as whatever
ambient identity was available — a different identity than the sync path uses.
Follows the same raise-on-unsupported approach as langchain-ai#1225.

Also replaces the credential test that asserted `asyncio.to_thread` was called
with one that measures the observable property: a heartbeat coroutine keeps
ticking while a slow credential resolution runs.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bedrock Mantle chat models silently reject unsupported guardrail headers

1 participant