litellm/tests/test_litellm/llms/bedrock
Ishaan Jaff b87d1f8dad
[Feat] - Ishaan main merge branch (#23596)
* fix(bedrock): respect s3_region_name for batch file uploads (#23569)

* fix(bedrock): respect s3_region_name for batch file uploads (GovCloud fix)

* fix: s3_region_name always wins over aws_region_name for S3 signing (Greptile feedback)

* fix: _filter_headers_for_aws_signature - Bedrock KB (#23571)

* fix: _filter_headers_for_aws_signature

* fix: filter None header values in all post-signing re-merge paths

Addresses Greptile feedback: None-valued headers were being filtered
during SigV4 signing but re-merged back into the final headers dict
afterward, which would cause downstream HTTP client failures.

Made-with: Cursor

* feat(router): tag_regex routing — route by User-Agent regex without per-developer tag config (#23594)

* feat(router): add tag_regex support for header-based routing

Adds a new `tag_regex` field to litellm_params that lets operators route
requests based on regex patterns matched against request headers — primarily
User-Agent — without requiring per-developer tag configuration.

Use case: route all Claude Code traffic (User-Agent: claude-code/x.y.z) to
a dedicated deployment by setting:

  tag_regex:
    - "^User-Agent: claude-code\\/"

in the deployment's litellm_params. Works alongside existing `tags` routing;
exact tag match takes precedence over regex match. Unmatched requests fall
through to deployments tagged `default`.

The matched deployment, pattern, and user_agent are recorded in
`metadata["tag_routing"]` so they flow through to SpendLogs automatically.

* fix(tag_regex): address backwards-compat, metadata overwrite, and warning noise

Three issues from code review:

1. Backwards-compat: `has_tag_filter` was widened to activate on any non-empty
   User-Agent, which would raise ValueError for existing deployments using plain
   tags without a `default` fallback. Fix: only activate header-based regex
   filtering when at least one candidate deployment has `tag_regex` configured.

2. Metadata overwrite: `metadata["tag_routing"]` was overwritten for every
   matching deployment in the loop, leaving inaccurate provenance when multiple
   deployments match. Fix: write only for the first match.

3. Warning noise: an invalid regex pattern logged one warning per header string
   rather than once per pattern. Fix: compile first (catching re.error once),
   then iterate over header strings.

Also adds two new tests covering these cases, and adds docs page for
tag_regex routing with a Claude Code walk-through.

* refactor(tag_regex): remove unnecessary _healthy_list copy

* docs: merge tag_regex section into tag_routing.md, remove standalone page

- Add ## Regex-based tag routing (tag_regex) section to existing
  tag_routing.md instead of a separate page
- Remove tag_regex_routing.md standalone doc (odd UX to have a separate
  page for a sub-feature)
- Remove proxy/tag_regex_routing from sidebars.js
- Add match_any=False debug warning in tag_based_routing.py when regex
  routing fires under strict mode (regex always uses OR semantics)

* fix(tag_regex): address greptile review - security docs, strict-mode enforcement, validation order

- Strengthen security note in tag_routing.md: explicitly state User-Agent
  is client-supplied and can be set to any value; frame tag_regex as a
  traffic classification hint, not an access-control mechanism
- Move tag_regex startup validation before _add_deployment() so an invalid
  pattern never leaves partial router state
- Enforce match_any=False strict-tag policy: when a deployment has both
  tags and tag_regex and the strict tag check fails, skip the regex fallback
  rather than silently bypassing the operator's intent
- Extract per-deployment match logic into _match_deployment() helper to
  keep get_deployments_for_tag() readable
- Add two new tests: strict-mode blocks regex fallback, regex-only
  deployment still matches under match_any=False

* fix(ci): apply Black formatting to 14 files and stabilize flaky caplog tests

- Run Black formatter on 14 files that were failing the lint check
- Replace caplog-based assertions in TestAliasConflicts with
  unittest.mock.patch on verbose_logger.warning for xdist compatibility
- The caplog fixture can produce empty text in pytest-xdist workers
  in certain CI environments, causing flaky test failures

Co-authored-by: Ishaan Jaff <ishaan-jaff@users.noreply.github.com>

---------

Co-authored-by: Cursor Agent <cursoragent@cursor.com>
Co-authored-by: Ishaan Jaff <ishaan-jaff@users.noreply.github.com>
2026-03-14 09:40:00 -07:00
..
chat merge: resolve conflicts with upstream staging (bedrock + mcp tests) 2026-03-12 13:40:16 -03:00
count_tokens fix(count_tokens): include system and tools in token counting API requests 2026-02-27 15:39:35 -03:00
embed fix(cost-calc): use per-image pricing for Bedrock multimodal embeddings (#21646) 2026-02-20 08:51:21 -08:00
files [Feat] - Ishaan main merge branch (#23596) 2026-03-14 09:40:00 -07:00
image fix patch 2025-12-20 14:00:42 +05:30
invoke_agent fix: use fastuuid helper (#14903) 2025-09-25 15:47:01 -07:00
messages/invoke_transformations fix(bedrock): strip output_config from Bedrock Invoke requests (#23042) 2026-03-07 19:33:53 -08:00
passthrough Fix : model id encoding for bedrock passthrough 2026-01-12 10:57:17 +05:30
realtime Add nova sonic tests 2026-02-02 12:18:43 +05:30
rerank fix(bedrock): pass timeout param to bedrock rerank http client (#22021) 2026-02-24 09:32:11 -08:00
vector_stores [Feat] UI Vector Stores - Allow adding Vertex RAG Engine, OpenAI, Azure (#12752) 2025-07-18 18:25:26 -07:00
test_anthropic_beta_support.py Update code to handle anthropic beta headers mapping 2026-02-11 12:35:22 +05:30
test_base_aws_llm.py [Feat] - Ishaan main merge branch (#23596) 2026-03-14 09:40:00 -07:00
test_bedrock_common_utils.py Fix: Support us-gov prefix for AWS GovCloud Bedrock models (#15626) 2025-10-17 13:19:51 -07:00
test_bedrock_ssl_verify.py [Bug]: Add Custom CA certificates to boto3 clients 2026-01-12 09:05:09 +05:30
test_cross_region_inference_profile_mapping.py Fix: Bedrock cross-region inference profile cost calculation (#14566) 2025-09-15 07:10:20 -07:00