This is an automated email from the ASF dual-hosted git repository.

wenjin272 pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/flink-agents.git


The following commit(s) were added to refs/heads/main by this push:
     new 9b4280b89 [python][integrations] Raise a clear error for an 
unrenderable output schema in the Ollama connection (#1276)
9b4280b89 is described below

commit 9b4280b89b4111f34c7eb426e1af8ad2c003460a
Author: wank125 <[email protected]>
AuthorDate: Mon Oct 19 14:22:54 2026 +0800

    [python][integrations] Raise a clear error for an unrenderable output 
schema in the Ollama connection (#1276)
---
 .../integrations/chat_models/ollama_chat_model.py    |  7 ++++---
 .../tests/test_ollama_native_structured_output.py    | 20 +++++++++++++++++++-
 2 files changed, 23 insertions(+), 4 deletions(-)

diff --git a/python/flink_agents/integrations/chat_models/ollama_chat_model.py 
b/python/flink_agents/integrations/chat_models/ollama_chat_model.py
index e8c8e08b0..b350e7c48 100644
--- a/python/flink_agents/integrations/chat_models/ollama_chat_model.py
+++ b/python/flink_agents/integrations/chat_models/ollama_chat_model.py
@@ -24,7 +24,7 @@ from ollama import Client, Image, Message
 from pydantic import BaseModel, Field
 from typing_extensions import override
 
-from flink_agents.api.agents.types import OutputSchema
+from flink_agents.api.agents.types import OutputSchema, render_output_schema
 from flink_agents.api.chat_message import (
     Base64Source,
     ChatMessage,
@@ -74,12 +74,13 @@ def _native_format(output_schema: Any) -> Dict[str, Any] | 
None:
 
     Returns ``None`` (leaving the request unconstrained) unless the schema is a
     ``BaseModel`` subclass. A ``RowTypeInfo`` schema is skipped so it keeps the
-    prompt-engineering fallback.
+    prompt-engineering fallback. A schema that cannot be rendered raises 
through
+    ``render_output_schema``, naming the model, like the other connections.
     """
     model = _native_output_model(output_schema)
     if model is None:
         return None
-    return model.model_json_schema()
+    return render_output_schema(model, lambda m: m.model_json_schema())
 
 
 class OllamaChatModelConnection(BaseChatModelConnection):
diff --git 
a/python/flink_agents/integrations/chat_models/tests/test_ollama_native_structured_output.py
 
b/python/flink_agents/integrations/chat_models/tests/test_ollama_native_structured_output.py
index 2405302bb..2c07423c1 100644
--- 
a/python/flink_agents/integrations/chat_models/tests/test_ollama_native_structured_output.py
+++ 
b/python/flink_agents/integrations/chat_models/tests/test_ollama_native_structured_output.py
@@ -15,7 +15,7 @@
 #  See the License for the specific language governing permissions and
 # limitations under the License.
 
#################################################################################
-from typing import Any, Dict, List, Mapping
+from typing import Any, Callable, Dict, List, Mapping
 from unittest.mock import MagicMock
 
 import pytest
@@ -47,6 +47,12 @@ class Company(BaseModel):
     owner: Person
 
 
+class Unrenderable(BaseModel):
+    """A schema carrying a member that no JSON Schema can express."""
+
+    cb: Callable[[int], int]
+
+
 def _connection() -> OllamaChatModelConnection:
     """A connection whose Ollama client is a mock, so no server is 
contacted."""
     conn = OllamaChatModelConnection()
@@ -113,6 +119,18 @@ def test_schema_is_model_json_schema() -> None:
     assert _chat_call_kwargs(conn)["format"] == Company.model_json_schema()
 
 
+def test_unrenderable_schema_raises_naming_the_model() -> None:
+    """A schema that cannot be rendered fails here, named, not at the 
provider."""
+    conn = _connection()
+    with pytest.raises(TypeError, match="Unrenderable cannot be rendered"):
+        conn.chat(
+            _messages(),
+            model="qwen3",
+            output_schema=OutputSchema(output_schema=Unrenderable),
+        )
+    conn.client.chat.assert_not_called()
+
+
 def test_schema_not_passed_as_sampling_option() -> None:
     """The schema never reaches ``options``, which the server reads as 
sampling options.
 

Reply via email to