wank125 opened a new pull request, #1276:
URL: https://github.com/apache/flink-agents/pull/1276
Linked issue: #985
### Purpose of change
**User-visible outcome.** An Ollama chat call whose `BaseModel` output
schema pydantic cannot render now fails with the shared, model-naming
`TypeError` ("Output schema ... Unrenderable ... cannot be rendered as a JSON
Schema ..."), instead of leaking pydantic's raw `PydanticInvalidForJsonSchema`
("Cannot generate a JsonSchema for core_schema.CallableSchema"). No HTTP
request is made in that case. This is the Ollama residual of #985: #1046
delivered the decided behavior for the Java base class and the Python
OpenAI/Azure/Anthropic connections, and DashScope/watsonx already route through
the shared helper, but `OllamaChatModelConnection` still called
`model.model_json_schema()` directly.
**Runtime flow.** `OllamaChatModelConnection.chat` →
`_native_format(output_schema)` → `_native_output_model` (unchanged) → now
`render_output_schema(model, lambda m: m.model_json_schema())`, the same helper
in `flink_agents/api/agents/types.py` that DashScope and watsonx use. On
success the produced document is returned as produced, so the `format` payload
is unchanged.
**Key decisions.** Reuse `render_output_schema` rather than a local
try/except, so the wording stays identical across connections and cannot drift;
a local copy would re-create the inconsistency #1046 removed. Rejected touching
`_native_output_model` — that restructuring is #1266's scope, not this fix's.
### Behavioral Semantics
#### Interaction decisions
| `output_schema` passed to `chat` | behavior |
|---|---|
| `None` or a `RowTypeInfo` | unchanged: no `format` argument,
prompt-engineering fallback |
| renderable `BaseModel` | unchanged: `model.model_json_schema()` sent
verbatim as `format` |
| `BaseModel` pydantic cannot render | changed: shared `TypeError` naming
the model, raised before the Ollama client is called |
#### Behavioral contracts
1. A renderable `BaseModel` reaches the request as the model's JSON Schema
verbatim, `` and all (unchanged).
2. A `BaseModel` that cannot be rendered raises a `TypeError` whose message
names the model class and says the schema cannot constrain the response, and no
request is sent to the Ollama server.
3. `None`/`RowTypeInfo` schemas never gain a native `format`; the prompt
fallback is kept (unchanged).
#### Failure behavior
An unrenderable `BaseModel` raises at schema-render time (`TypeError`
chained from the pydantic error) rather than falling back to the prompt path —
per the decision recorded on #985, because the prompt fallback also has to
render the schema and would fail the same way. All other failure paths (server
errors, malformed responses) are untouched.
#### Compatibility impact
Changed: a caller that previously caught pydantic's
`PydanticInvalidForJsonSchema` now sees the shared `TypeError`; code catching
`TypeError` (which the pydantic error subclasses) keeps working. Unchanged:
every request that succeeded before, byte-identically, and all other
connections.
### Tests
| contract | test |
|---|---|
| renderable payload sent verbatim | `test_schema_is_model_json_schema`
(existing) |
| unrenderable raises named `TypeError`, no request |
`test_unrenderable_schema_raises_naming_the_model` (new; fails on the
pre-change code with the raw pydantic error, passes after) |
| `None`/`RowTypeInfo` keep the fallback |
`test_format_absent_without_schema`,
`test_native_not_applied_for_row_type_info` (existing) |
Not verified: nothing new — the change adds no runtime path beyond wrapping
the existing render call.
Local run (macOS, python 3.11, pydantic pinned 2.11.4): 76 tests across the
Ollama and DashScope test modules, and 210 tests across
`flink_agents/api/agents/tests`, `flink_agents/api/chat_models`,
`flink_agents/integrations/chat_models/tests` (integration-marked deselected)
all pass; `ruff check` (0.11.13) passes on both changed files.
### API
No public API change. The touched functions are module-private; the
observable difference is the exception type/message described above.
### Documentation
- [x] `doc-not-needed`
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]