Skip to content

feat: add response_format json_object support#123

Open
lukasBlckIT wants to merge 2 commits intojwadow:mainfrom
BlckIT:feat/response-format-json-object
Open

feat: add response_format json_object support#123
lukasBlckIT wants to merge 2 commits intojwadow:mainfrom
BlckIT:feat/response-format-json-object

Conversation

@lukasBlckIT
Copy link
Copy Markdown

Problem

When response_format: {"type": "json_object"} is set, kiro-gateway accepts the parameter but does not forward it to the Kiro API. Claude responds with markdown-wrapped JSON (json ... ) instead of raw JSON, causing JSON parsing failures in downstream clients (e.g. ValidationError in Honcho).

Solution

Two-layer fix:

  1. System prompt injection (kiro/converters_openai.py) — when response_format: json_object is detected, appends a JSON instruction to the system prompt telling Claude to respond with raw JSON only, no markdown wrappers.

  2. Markdown stripping (kiro/routes_openai.py + new kiro/json_response_format.py) — post-processes non-streaming responses to strip any remaining markdown code block wrappers as a fallback.

Behaviour

  • response_format: json_object → raw, parseable JSON guaranteed
  • response_format: text or no response_format → completely unaffected
  • Streaming: system prompt injection is sufficient per OpenAI spec (chunks are text deltas, not full responses)
  • Existing system prompts are preserved and the JSON instruction is appended

Testing

25/25 test cases passed locally, covering non-streaming, streaming, Swedish unicode characters, tool calling, auth errors, and edge cases.

@cla-bot
Copy link
Copy Markdown

cla-bot bot commented Apr 2, 2026

Thanks for the PR! 🎉

Before merge, we need a one-time CLA confirmation.
It confirms that you have the right to contribute this code and allow the project to use it.

Full CLA text:
https://github.com/jwadow/kiro-gateway/blob/main/CLA.md

Please reply once with:

I have read the CLA and I accept its terms

You need to write once, all further messages from me can be ignored.

@cla-bot
Copy link
Copy Markdown

cla-bot bot commented Apr 4, 2026

Thanks for the PR! 🎉

Before merge, we need a one-time CLA confirmation.
It confirms that you have the right to contribute this code and allow the project to use it.

Full CLA text:
https://github.com/jwadow/kiro-gateway/blob/main/CLA.md

Please reply once with:

I have read the CLA and I accept its terms

You need to write once, all further messages from me can be ignored.

@lukasBlckIT
Copy link
Copy Markdown
Author

I have read the CLA and I accept its terms

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.

1 participant