Skip to content

feat(bedrock): pass strict and additionalProperties to Converse API toolSpec - #25209

Closed
Ryze0323 wants to merge 1 commit into
BerriAI:mainfrom
Ryze0323:feat/bedrock-strict-tool-support
Closed

feat(bedrock): pass strict and additionalProperties to Converse API toolSpec#25209
Ryze0323 wants to merge 1 commit into
BerriAI:mainfrom
Ryze0323:feat/bedrock-strict-tool-support

Conversation

@Ryze0323

@Ryze0323 Ryze0323 commented Apr 5, 2026

Copy link
Copy Markdown

Relevant issues

Closes the gap where Anthropic direct API path already supports strict (PR #16725) but Bedrock Converse path does not.

Related: #10062, #16725, #6136

Summary

Bedrock Converse API supports strict: true in toolSpec since 2026-02-04 (GA) — AWS API Reference: ToolSpecification.

Previously, both strict and additionalProperties were implicitly dropped during OpenAI-to-Bedrock tool conversion because ToolSpecBlock and ToolJsonSchemaBlock only whitelisted a subset of fields (introduced in #10062, which was correct at the time since Bedrock didn't support strict).

Without additionalProperties: false in the schema, Bedrock rejects strict: true requests with:

"For 'object' type, 'additionalProperties' must be explicitly set to false"

This PR:

  • Adds strict: Optional[bool] to ToolSpecBlock TypedDict
  • Adds additionalProperties: bool to ToolJsonSchemaBlock TypedDict
  • Passes through both parameters in _bedrock_tools_pt() when present
  • Adds unit test verifying both fields are passed through (and absent when not specified)

Pre-Submission checklist

  • I have Added testing in the tests/test_litellm/ directory, Adding at least 1 test is a hard requirement - see details
  • My PR passes all unit tests on make test-unit
  • My PR's scope is as isolated as possible, it only solves 1 specific problem
  • I have requested a Greptile review by commenting @greptileai and received a Confidence Score of at least 4/5 before requesting a maintainer review

Type

🆕 New Feature

Changes

  • litellm/types/llms/bedrock.py: Added strict: Optional[bool] to ToolSpecBlock, additionalProperties: bool to ToolJsonSchemaBlock
  • litellm/litellm_core_utils/prompt_templates/factory.py: Pass through strict and additionalProperties from OpenAI tool format to Bedrock toolSpec
  • tests/llm_translation/test_bedrock_completion.py: Updated test_bedrock_tools_pt_strict_parameter test to cover both fields

@vercel

vercel Bot commented Apr 5, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
litellm Ready Ready Preview, Comment Apr 8, 2026 3:56am

Request Review

@Ryze0323

Ryze0323 commented Apr 6, 2026

Copy link
Copy Markdown
Author

@greptileai - Updated: applied P2 style feedback (dict-spread instead of post-construction mutation)

@greptile-apps

greptile-apps Bot commented Apr 6, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR closes the gap between the Anthropic direct API path (which already supports strict) and the Bedrock Converse path by passing strict and additionalProperties through _bedrock_tools_pt() to the Bedrock toolSpec. The changes are minimal and well-scoped: two TypedDict fields are added, the conversion function is updated with proper None-safe conditional dict-spread, and a focused unit test validates both the pass-through and the absence cases.

Key changes:

  • ToolJsonSchemaBlock gains additionalProperties: bool — required by Bedrock when strict: true is requested (Bedrock returns an error without it)
  • ToolSpecBlock gains strict: Optional[bool] — minor nit: since the TypedDict is already total=False, plain bool would be cleaner (see inline comment)
  • _bedrock_tools_pt() correctly guards both fields with is not None checks, so additionalProperties: False (falsy but valid) is still forwarded
  • The test covers the two main branches: both fields present and neither field present

Confidence Score: 5/5

Safe to merge — only one P2 style nit remains; no correctness or reliability issues.

The change is narrow and correct: two optional fields are forwarded through an existing conversion function with proper falsy-safe guards. The test validates both the pass-through and absence paths. The only open finding is a P2 type-annotation nit (Optional[bool] vs bool in a total=False TypedDict) which has no runtime impact.

No files require special attention.

Vulnerabilities

No security concerns identified. The change only passes through user-supplied schema fields (strict, additionalProperties) to the Bedrock Converse API — no auth, credential, or injection surface is touched.

Important Files Changed

Filename Overview
litellm/types/llms/bedrock.py Adds additionalProperties: bool to ToolJsonSchemaBlock and strict: Optional[bool] to ToolSpecBlock; minor nit: Optional[bool] in a total=False TypedDict allows None values that the production code deliberately avoids.
litellm/litellm_core_utils/prompt_templates/factory.py Correctly extracts additionalProperties from parameters and strict from tool["function"], passing each through only when non-None via dict-spread; logic is clean and handles False (falsy) values properly.
tests/llm_translation/test_bedrock_completion.py New unit test covers both the "with strict + additionalProperties" and "without either field" paths; no network calls; could also test each field independently but the primary scenarios are exercised.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A["OpenAI tool format\n{ function: { name, strict, parameters: { ..., additionalProperties } } }"] --> B["_bedrock_tools_pt()"]
    B --> C{additionalProperties\nin parameters?}
    C -- yes --> D["Include additionalProperties\nin BedrockToolJsonSchemaBlock"]
    C -- no --> E["Omit additionalProperties"]
    D --> F["BedrockToolInputSchemaBlock"]
    E --> F
    B --> G{strict in\nfunction?}
    G -- yes --> H["Include strict\nin BedrockToolSpecBlock"]
    G -- no --> I["Omit strict"]
    F --> J["BedrockToolSpecBlock\n{ inputSchema, name, description, [strict] }"]
    H --> J
    I --> J
    J --> K["BedrockToolBlock\n{ toolSpec: ... }"]
    K --> L["Bedrock Converse API"]
Loading

Reviews (7): Last reviewed commit: "feat(bedrock): pass strict and additiona..." | Re-trigger Greptile

Comment thread litellm/litellm_core_utils/prompt_templates/factory.py Outdated
@Ryze0323

Ryze0323 commented Apr 6, 2026

Copy link
Copy Markdown
Author

@ishaan-jaff @krrishdholakia This PR is ready for review — all CI checks pass and Greptile gave 5/5 confidence. Could you take a look when you get a chance? Thanks!

@Ryze0323

Ryze0323 commented Apr 8, 2026

Copy link
Copy Markdown
Author

@greptileai review

@codspeed-hq

codspeed-hq Bot commented Apr 8, 2026

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

✅ 16 untouched benchmarks


Comparing Ryze0323:feat/bedrock-strict-tool-support (c51fb46) with main (62757ff)

Open in CodSpeed

@codecov

codecov Bot commented Apr 8, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@Ryze0323 Ryze0323 changed the title feat(bedrock): pass strict parameter to Converse API toolSpec feat(bedrock): pass strict and additionalProperties to Converse API toolSpec Apr 8, 2026
@Ryze0323
Ryze0323 force-pushed the feat/bedrock-strict-tool-support branch from 06b7252 to ccae41e Compare April 8, 2026 01:52
@Ryze0323
Ryze0323 force-pushed the feat/bedrock-strict-tool-support branch from ccae41e to 0b69b15 Compare April 8, 2026 02:07
@Ryze0323
Ryze0323 force-pushed the feat/bedrock-strict-tool-support branch from 0b69b15 to 6e93431 Compare April 8, 2026 02:21
@Ryze0323
Ryze0323 force-pushed the feat/bedrock-strict-tool-support branch from 6e93431 to 38c188c Compare April 8, 2026 03:53
…oolSpec

Bedrock Converse API supports strict: true in toolSpec since 2026-02-04 (GA).
Previously, both strict and additionalProperties were implicitly dropped
during OpenAI-to-Bedrock tool conversion because ToolSpecBlock and
ToolJsonSchemaBlock only whitelisted a subset of fields.

This change:
- Adds strict to ToolSpecBlock and passes it through when present
- Adds additionalProperties to ToolJsonSchemaBlock and passes it through
  when present (required by Bedrock when strict: true is set)

Without additionalProperties: false, Bedrock rejects strict: true requests
with: "For 'object' type, 'additionalProperties' must be explicitly set to false"

Fixes the gap where Anthropic direct API path already supports strict
(PR BerriAI#16725) but Bedrock Converse path does not.
@Ryze0323

Ryze0323 commented Apr 8, 2026

Copy link
Copy Markdown
Author

@yuneng-berri Could you take a look when you get a chance? All CI checks pass and Greptile gave 5/5 confidence. Thanks!

@github-actions

github-actions Bot commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

@github-actions github-actions Bot added the stale label Jul 8, 2026
@github-actions github-actions Bot closed this Jul 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant