Various Fixes (#22594)

* Fix handling of preview

* Fix schema cleaning

* Cleanup
This commit is contained in:
Nicolas Mowen
2026-03-23 11:22:52 -05:00
committed by GitHub
parent a89c7d8819
commit a8b6ea5005
6 changed files with 29 additions and 23 deletions
+9 -3
View File
@@ -54,12 +54,16 @@ class OllamaClient(GenAIClient):
return None
@staticmethod
def _clean_schema_for_ollama(schema: dict) -> dict:
def _clean_schema_for_ollama(schema: dict, *, _is_properties: bool = False) -> dict:
"""Strip Pydantic metadata from a JSON schema for Ollama compatibility.
Ollama's grammar-based constrained generation works best with minimal
schemas. Pydantic adds title/description/constraint fields that can
cause the grammar generator to silently skip required fields.
Keys inside a ``properties`` dict are actual field names and must never
be stripped, even if they collide with a metadata key name (e.g. a
model field called ``title``).
"""
STRIP_KEYS = {
"title",
@@ -71,10 +75,12 @@ class OllamaClient(GenAIClient):
}
result = {}
for key, value in schema.items():
if key in STRIP_KEYS:
if not _is_properties and key in STRIP_KEYS:
continue
if isinstance(value, dict):
result[key] = OllamaClient._clean_schema_for_ollama(value)
result[key] = OllamaClient._clean_schema_for_ollama(
value, _is_properties=(key == "properties")
)
elif isinstance(value, list):
result[key] = [
OllamaClient._clean_schema_for_ollama(item)