Files
litellm/tests/test_litellm/llms/sap
Guilherme Segantini e335dd70f8 fix(sap provider layer): enable response-format for anthropic models and improve compatibility for GPT models via LangChain (#22804)
* (sap) ensure tool parameters have type='object' for SAP compatibility

Fix SAP GenAI Hub Orchestration Service rejecting tool calls with error:
"400 - LLM Module: tools.0.custom.input_schema.type: Input should be 'object'"

Root cause: When Claude Code uses tools (like web_search) with the SAP provider
through LiteLLM's Anthropic experimental pass-through adapter, Anthropic's
input_schema format doesn't always include the required type="object" field.

The adapter's translate_anthropic_tools_to_openai() function was directly
copying input_schema to OpenAI's parameters field without ensuring the
type="object" requirement that SAP's API strictly enforces.

Changes:
- Modified translate_anthropic_tools_to_openai() to check if input_schema
  is missing the type field and add type="object" if absent
- Preserves existing type field if already present
- Added comprehensive test suite (6 tests) covering:
  - Missing type field scenario (now adds type="object")
  - Existing type preservation
  - Empty input_schema handling
  - Multiple tools transformation
  - Additional schema properties preservation
  - SAP-specific compatibility regression test

Testing:
- All new tests pass (6/6 in test_anthropic_tool_schema_fix.py)
- All existing Anthropic tool tests pass (57/57 tool-related tests)
- SAP tool parameter validation tests pass (9/9 in test_sap_tool_parameters.py)

* (sap) enable native response_format for anthropic models

* (sap) filter strict param from model_params for GPT models only

* (sap) revert Anthropic adapter type='object' fix

The SAP FunctionTool Pydantic validator in litellm/llms/sap/chat/models.py
already ensures type='object' is added to all tool parameters for SAP
API compatibility.

The Anthropic adapter change affected ALL consumers, not just SAP, which
was broader scope than intended for this PR.

- Revert input_schema modification in Anthropic adapter
- Remove Anthropic-specific test file (SAP tests still cover this case)

* (sap) gate markdown stripping to Anthropic models only

SAP GenAI Hub with Anthropic models sometimes returns JSON wrapped in
markdown code blocks. GPT/Gemini/Mistral models don't exhibit this
behavior, so stripping is now gated to avoid accidentally modifying
valid responses that may contain markdown in JSON string values.
2026-03-04 16:03:59 -08:00
..