Skip to content

fix(providers): Responses API tool schema and null error handling#790

Merged
DonPrus merged 1 commit intonullclaw:mainfrom
fakhriaunur:pr/fix-responses-api-tool-schema
Apr 16, 2026
Merged

fix(providers): Responses API tool schema and null error handling#790
DonPrus merged 1 commit intonullclaw:mainfrom
fakhriaunur:pr/fix-responses-api-tool-schema

Conversation

@fakhriaunur
Copy link
Copy Markdown
Contributor

@fakhriaunur fakhriaunur commented Apr 8, 2026

Summary

Fix two bugs in the OpenAI-compatible provider's Responses API (api_mode=responses) code path:

  • Tool schema format: buildResponsesRequestBody used convertToolsOpenAI which produces nested Chat Completions format ({"type":"function","function":{"name":...}}). Responses API requires flat format ({"type":"function","name":...}). Added convertToolsResponses() producing the correct flat format.
  • Null error misclassification: classifyErrorObject returned .other when response contained "error": null (JSON null), causing valid responses to be rejected as API errors. Added null guard before the .object check.

Changes

File Change
src/providers/helpers.zig Add convertToolsResponses() — flat tool schema format
src/providers/root.zig Export convertToolsResponses
src/providers/compatible.zig:548 Wire convertToolsResponses into buildResponsesRequestBody
src/providers/error_classify.zig:312 Add null guard: if (err_value == .null) return null;

Tests

  • convertToolsResponses produces flat format — verifies no nested "function" wrapper, "name" at top level
  • convertToolsResponses empty tools — verifies [] for empty input
  • classifyKnownApiError returns null for error:null — verifies null error is not classified
  • parseResponsesResponse handles error:null without returning error — verifies content extraction despite null error
  • Updated buildResponsesRequestBody includes tools and tool results — adds flat format assertions

Validation

  • zig build — compiles clean
  • zig fmt --check src/ — passes
  • 4 files changed, +99/-1 lines

Approach Comparison

This PR addresses the same bugs as #772 (@telagod). Both share the same fix approach:

Aspect #772 (telagod) #790 (this PR)
convertToolsResponses ✅ Same flat format ✅ Same flat format
Null guard in classifyErrorObject ✅ 1-line fix ✅ 1-line fix
Wire into buildResponsesRequestBody
Tests for convertToolsResponses ✅ 2 tests
Test for "error": null classification ✅ 1 test
Test for parseResponsesResponse with null error ✅ 1 test
Updated existing test with flat assertion

This PR is functionally equivalent to #772 but adds test coverage for both fixes (5 new tests + 1 updated), following the repo's mandate that "every code change must be accompanied by tests, no exceptions" (AGENTS.md §8.1).

Supersedes

Supersedes #772 — identical production fix + comprehensive test coverage.

Fixes #773

@fakhriaunur fakhriaunur marked this pull request as draft April 9, 2026 02:47
@fakhriaunur fakhriaunur force-pushed the pr/fix-responses-api-tool-schema branch 2 times, most recently from f993872 to a1d8d4f Compare April 9, 2026 03:11
@fakhriaunur fakhriaunur marked this pull request as ready for review April 9, 2026 03:23
Fix two bugs in the Responses API (api_mode=responses) code path:

1. Tool schema format: buildResponsesRequestBody used convertToolsOpenAI
   which produces nested Chat Completions format
   ({"type":"function","function":{"name":...}}). Responses API
   requires flat format ({"type":"function","name":...}).
   - Add convertToolsResponses() in helpers.zig producing flat format
   - Wire into buildResponsesRequestBody (compatible.zig:548)
   - Export convertToolsResponses in root.zig

2. Null error misclassification: classifyErrorObject returned .other
   when response contained "error": null (JSON null), causing valid
   responses to be rejected as API errors.
   - Add null guard: if (err_value == .null) return null

Tests:
- convertToolsResponses produces flat format (no nested "function")
- convertToolsResponses empty tools
- classifyKnownApiError returns null for error:null
- parseResponsesResponse handles error:null without returning error
- buildResponsesRequestBody tools use flat schema (updated existing test)

Fixes nullclaw#773
@DonPrus DonPrus force-pushed the pr/fix-responses-api-tool-schema branch from c911359 to 95b5b2e Compare April 16, 2026 20:11
@DonPrus DonPrus merged commit b1394ee into nullclaw:main Apr 16, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: Responses API (api_mode=responses) broken — tool schema format and null error misclassification

2 participants