Skip to content

[integrations][java][python] Preserve Watsonx finish_reason in extra_args - #1113

Open
Ashfaqbs wants to merge 1 commit into
apache:mainfrom
Ashfaqbs:feat/watsonx-finish-reason
Open

[integrations][java][python] Preserve Watsonx finish_reason in extra_args#1113
Ashfaqbs wants to merge 1 commit into
apache:mainfrom
Ashfaqbs:feat/watsonx-finish-reason

Conversation

@Ashfaqbs

Copy link
Copy Markdown
Contributor

Linked issue: #1106 (Watsonx portion; the Anthropic portion is covered separately by #1107)

Purpose of change

Watsonx's chat response already carries a finish_reason in the shared OpenAI-compatible vocabulary (stop, tool_calls, etc.), but the connection only used it to emit a log warning and never surfaced it to callers. This preserves it verbatim in extra_args["finish_reason"], mirroring the existing OpenAI/Azure OpenAI connection behavior, for both the Java and Python connections.

  • A present, non-null reason is copied verbatim into extra_args["finish_reason"], including values outside stop/tool_calls.
  • A missing or JSON-null reason adds no key (matches the OpenAI connection's documented contract).
  • The existing "response may be truncated" log warning is unchanged.
  • Capture is independent of the token-usage metadata branch (verified with a case that has a finish reason but no usage block).

Tests

  • Java: WatsonxChatModelConnectionTest — added 4 tests covering a documented reason, an unrecognized/vendor-specific reason stored verbatim, absent finish_reason member, JSON-null finish_reason, and a reason captured without usage metadata present. mvn test -Dtest=WatsonxChatModelConnectionTest → 24 passed.
  • Python: test_watsonx_chat_model.py — added 2 tests (unknown reason verbatim, no key when None) and asserted finish_reason in the existing mocked-chat test. pytest -m "not integration" → 14 passed.
  • mvn spotless:check and ruff check/ruff format --diff both clean on the touched files.

API

No public API signature changes; adds a new, optional key to the existing extra_args metadata map returned by both connections.

Documentation

  • doc-needed
  • doc-not-needed
  • doc-included

Was this patch authored or co-authored using generative AI tooling?

  • Yes

Generated-by: Claude Code 2.1.226 (Claude Sonnet 5)

…args

Fixes apache#1106 (Watsonx portion). The Anthropic portion is covered
separately by apache#1107. Watsonx already emits the shared finish_reason
vocabulary (stop/tool_calls/etc.), so the value is retained verbatim
in extra_args["finish_reason"] instead of only being used for a log
warning. A missing or JSON-null reason adds no key, matching the
OpenAI/Azure OpenAI connection's existing behavior.

Generated-by: Claude Code 2.1.226 (Claude Sonnet 5)
@github-actions github-actions Bot added doc-not-needed Your PR changes do not impact docs fixVersion/0.4.0 priority/major Default priority of the PR or issue. labels Sep 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

doc-not-needed Your PR changes do not impact docs fixVersion/0.4.0 priority/major Default priority of the PR or issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant