You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by "weiqingy (via GitHub)" <gi...@apache.org> on 2026/08/08 21:51:48 UTC

[I] [Bug] An output schema pydantic cannot render raises instead of taking the prompt fallback [flink-agents]

weiqingy opened a new issue, #985:
URL: https://github.com/apache/flink-agents/issues/985

   ### Search before asking
   
   - [x] I searched in the [issues](https://github.com/apache/flink-agents/issues) and found nothing similar.
   
   ### Description
   
   `OllamaChatModelConnection.chat` translates a `BaseModel` output schema by calling `model_json_schema()`. For some field types pydantic cannot produce a JSON Schema and raises `PydanticInvalidForJsonSchema`, so the chat call fails instead of falling back to the prompt-engineering path.
   
   That is inconsistent with how the same connection treats the other schema form it cannot translate natively. A `RowTypeInfo` is skipped silently and the caller keeps the prompt fallback, while a `BaseModel` pydantic cannot render propagates an exception out of `chat`. Both cases are "this connection cannot express the schema natively", so it is not obvious they should behave differently.
   
   There are two defensible directions, and I do not think the choice is clear cut:
   
   1. Treat an unrenderable `BaseModel` like any other untranslatable schema and fall back to the prompt path. This makes the two cases consistent and keeps a schema from breaking a call that would otherwise succeed.
   2. Keep raising, on the grounds that an unrenderable schema is a caller mistake and a silent fallback would hide it, and instead make the `RowTypeInfo` case louder.
   
   The choice also affects what "capable" means. The connection reports native support for every model, so the caller has no way to ask in advance whether a particular schema will translate.
   
   Exposure today is limited. No framework path passes an `output_schema` down to a connection, so this is reachable only from a direct call to the 4-arg `chat`.
   
   The OpenAI, Azure OpenAI and Anthropic Python connections hand the class to their provider SDK rather than calling `model_json_schema()` themselves, so they raise from inside the SDK on the same input. Whatever is decided here likely applies to them as well, which is why this is filed against the behavior rather than against one connection.
   
   ### How to reproduce
   
   ```python
   from typing import Callable
   
   from pydantic import BaseModel
   
   from flink_agents.api.agents.types import OutputSchema
   
   
   class Bad(BaseModel):
       cb: Callable[[int], int]
   
   
   # raises pydantic.errors.PydanticInvalidForJsonSchema
   connection.chat(
       messages, model="qwen3", output_schema=OutputSchema(output_schema=Bad)
   )
   ```
   
   `Bad.model_json_schema()` on its own raises the same error, which is the call the connection makes.
   
   ### Version and environment
   
   Flink Agents `main` (0.3-SNAPSHOT), pydantic 2.11.4, Python 3.10 to 3.12. Not platform specific.
   
   ### Are you willing to submit a PR?
   
   - [x] I'm willing to submit a PR!
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] [Bug] An output schema pydantic cannot render raises instead of taking the prompt fallback [flink-agents]

Posted by "weiqingy (via GitHub)" <gi...@apache.org>.
weiqingy commented on issue #985:
URL: https://github.com/apache/flink-agents/issues/985#issuecomment-5323837354

   Thanks for the feedback @wenjin272.
   
   Option 2 also turns out to be the only workable one. The prompt fallback cannot render this schema either: `ReActAgent` builds its instruction prompt by rendering the schema (`python/flink_agents/api/agents/react_agent.py:130`), so an unrenderable model already raises there, before any connection is involved. There is no schema left to put in the prompt.
   
   One correction to my own issue while I am here: the Ollama `model_json_schema()` call I cited is in #981, not on `main`.
   
   I will open a PR and we can go through the implementation in review.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] [Bug] An output schema pydantic cannot render raises instead of taking the prompt fallback [flink-agents]

Posted by "wenjin272 (via GitHub)" <gi...@apache.org>.
wenjin272 closed issue #985: [Bug] An output schema pydantic cannot render raises instead of taking the prompt fallback
URL: https://github.com/apache/flink-agents/issues/985


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] [Bug] An output schema pydantic cannot render raises instead of taking the prompt fallback [flink-agents]

Posted by "wenjin272 (via GitHub)" <gi...@apache.org>.
wenjin272 commented on issue #985:
URL: https://github.com/apache/flink-agents/issues/985#issuecomment-5312409060

   I lean toward option 2. A `BaseModel` that Pydantic cannot render is invalid for structured output, and silently falling back would hide a caller error while weakening the schema guarantee. We should raise a clear, consistent error across connections, while treating `RowTypeInfo` as a separate, explicitly documented fallback case.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org