fix(types): revert azure search, milvus and onyx response validation to main
Some checks failed
LiteLLM Rust / rust-lint (push) Has been cancelled
LiteLLM Rust / rust-test (push) Has been cancelled
LiteLLM Rust / rust-wheel (push) Has been cancelled
Terraform Provider / gofmt, vet, build, test (push) Has been cancelled
Terraform Provider / Provider endpoints vs proxy OpenAPI schema (push) Has been cancelled

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
mateo 2026-10-20 09:41:13 +00:00
parent 1c5911f62b
commit e69fa73a5f
3 changed files with 11 additions and 65 deletions

View file

@ -4,8 +4,6 @@ from collections.abc import Mapping, Sequence
from typing import TYPE_CHECKING, Any, Final
import httpx
from pydantic import ConfigDict, TypeAdapter, with_config
from typing_extensions import NotRequired, ReadOnly, TypedDict
from litellm.llms.azure.common_utils import BaseAzureLLM
from litellm.llms.base_llm.vector_store.transformation import (
@ -32,26 +30,6 @@ else:
LiteLLMLoggingObj = Any
_AzureSearchHit = with_config(ConfigDict(extra="allow", strict=True))(
TypedDict(
"_AzureSearchHit",
{
"id": NotRequired[ReadOnly[str | None]],
"content": NotRequired[ReadOnly[str | None]],
"@search.score": NotRequired[ReadOnly[int | float | None]],
},
)
)
@with_config(ConfigDict(extra="allow", strict=True))
class _AzureSearchResponse(TypedDict):
value: NotRequired[ReadOnly[Sequence[_AzureSearchHit]]]
_AZURE_SEARCH_RESPONSE: Final = TypeAdapter(_AzureSearchResponse)
class AzureAIVectorStoreConfig(BaseQueryEmbeddingVectorStoreConfig, BaseAzureLLM):
"""
Configuration for Azure AI Search Vector Store
@ -220,7 +198,7 @@ class AzureAIVectorStoreConfig(BaseQueryEmbeddingVectorStoreConfig, BaseAzureLLM
}
"""
try:
response_json: Final = _AZURE_SEARCH_RESPONSE.validate_python(response.json())
response_json: Final = response.json()
# Extract results from Azure AI Search API response
results: Final = response_json.get("value", [])

View file

@ -4,8 +4,6 @@ from collections.abc import Mapping, Sequence
from typing import TYPE_CHECKING, Any, Final
import httpx
from pydantic import ConfigDict, TypeAdapter, with_config
from typing_extensions import NotRequired, ReadOnly, TypedDict
from litellm.llms.base_llm.vector_store.transformation import (
BaseQueryEmbeddingVectorStoreConfig,
@ -31,20 +29,6 @@ if TYPE_CHECKING:
else:
LiteLLMLoggingObj = Any
@with_config(ConfigDict(extra="allow", strict=True))
class _MilvusSearchResponse(TypedDict):
data: ReadOnly[NotRequired[Sequence[Mapping[str, object]]]]
_MILVUS_SEARCH_RESPONSE: Final = TypeAdapter(_MilvusSearchResponse)
_MILVUS_SEARCH_TEXT: Final[TypeAdapter[str | None]] = TypeAdapter(
str | None, config=ConfigDict(strict=True, hide_input_in_errors=True)
)
_MILVUS_SEARCH_SCORE: Final[TypeAdapter[int | float | None]] = TypeAdapter(
int | float | None, config=ConfigDict(strict=True, hide_input_in_errors=True)
)
MILVUS_OPTIONAL_PARAMS: Final = {
"annsField",
"limit",
@ -227,7 +211,7 @@ class MilvusVectorStoreConfig(BaseQueryEmbeddingVectorStoreConfig):
}
"""
try:
response_json: Final = _MILVUS_SEARCH_RESPONSE.validate_python(response.json())
response_json: Final = response.json()
# Extract results from Azure AI Search API response
results: Final = response_json.get("data", [])
@ -247,7 +231,7 @@ class MilvusVectorStoreConfig(BaseQueryEmbeddingVectorStoreConfig):
search_results: Final[list[VectorStoreSearchResult]] = []
for result in results:
# Extract text content
text_content = _MILVUS_SEARCH_TEXT.validate_python(result.get(text_field, ""))
text_content = result.get(text_field, "")
content = [
VectorStoreResultContent(
@ -257,13 +241,14 @@ class MilvusVectorStoreConfig(BaseQueryEmbeddingVectorStoreConfig):
]
# Get the search score (distance from the query vector)
score = _MILVUS_SEARCH_SCORE.validate_python(result.get("distance", 0.0))
score = result.get("distance", 0.0)
# Build attributes with all available metadata
# Exclude system fields and already-processed fields
attributes = {
key: value for key, value in result.items() if key not in ["id", "content", "distance", text_field]
}
attributes = {}
for key, value in result.items():
if key not in ["id", "content", "distance", text_field]:
attributes[key] = value
result_obj = VectorStoreSearchResult(
score=score,

View file

@ -10,8 +10,6 @@ from typing import TYPE_CHECKING, Final, Literal, Optional
import httpx
from fastapi import HTTPException
from pydantic import ConfigDict, TypeAdapter, with_config
from typing_extensions import NotRequired, ReadOnly, TypedDict
from litellm._logging import verbose_proxy_logger
from litellm.integrations.custom_guardrail import (
@ -30,21 +28,6 @@ if TYPE_CHECKING:
from litellm.types.proxy.guardrails.guardrail_hooks.base import GuardrailConfigModel
@with_config(ConfigDict(extra="allow", strict=True))
class _GuardResult(TypedDict, total=False):
allowed: ReadOnly[object]
violated_rules: ReadOnly[NotRequired[list[str]]]
@with_config(ConfigDict(extra="allow", strict=True))
class _ModelResponseJson(TypedDict, total=False):
response: ReadOnly[object]
_GUARD_RESULT: Final = TypeAdapter(_GuardResult)
_MODEL_RESPONSE_JSON: Final = TypeAdapter(_ModelResponseJson)
class OnyxGuardrail(CustomGuardrail):
@classmethod
def get_supported_event_hooks(cls) -> list[GuardrailEventHooks]:
@ -83,7 +66,7 @@ class OnyxGuardrail(CustomGuardrail):
payload: object,
input_type: Literal["request", "response"],
conversation_id: str,
) -> _GuardResult:
) -> dict:
"""
Call external Onyx Guard server for validation
"""
@ -99,7 +82,7 @@ class OnyxGuardrail(CustomGuardrail):
},
)
response.raise_for_status()
result: Final[_GuardResult] = _GUARD_RESULT.validate_python(response.json())
result: Final = response.json()
if not result.get("allowed", True):
detection_message = "Unknown violation"
if "violated_rules" in result:
@ -131,7 +114,7 @@ class OnyxGuardrail(CustomGuardrail):
else:
try:
response: Final = ModelResponse(**request_data)
parsed: Final[_ModelResponseJson] = _MODEL_RESPONSE_JSON.validate_python(response.json())
parsed: Final = response.json()
payload = parsed.get("response", {})
except Exception as e:
verbose_proxy_logger.error(