fix: strip json_object fence on streaming (aggregated) path#13
Closed
Abhinavexist wants to merge 1 commit into
Closed
fix: strip json_object fence on streaming (aggregated) path#13Abhinavexist wants to merge 1 commit into
Abhinavexist wants to merge 1 commit into
Conversation
Non-stream create() unwraps the ```json fence Interfaze wraps json_object content in, but streaming didn't: stream() discarded the strip flag and _State.build() never unwrapped it, so get_final_completion() leaked the fence on json_object streams. Thread the flag from stream() into InterfazeStream/AsyncInterfazeStream and apply strip_json_fence in build(); scoped to the aggregated result (the live delta path is untouched). Moved strip_json_fence into _stream.py (shared with _chat) to avoid a circular import. Forward-compatible with the server-side fix in InterfazeAI/interfaze#218.
This was referenced Jul 18, 2026
Collaborator
Author
|
Superseded by #16, which consolidates the #218 spec-compat reconciliation (this fence fix + the max_completion_tokens/models alignment). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Found while auditing the SDK against server PR InterfazeAI/interfaze#218 (OpenAI 1:1 spec-compat).
Problem
Interfaze wraps
response_format: {"type": "json_object"}output in a```jsonfence. Non-streamcreate()unwraps it (to_interfaze'sstripflag), but the streaming path did not:stream()discarded the strip flag (kw, _ = self._kwargs(...)), and_State.build()never calledstrip_json_fence,so
get_final_completion()returned the raw fenced string forjson_objectstreams — inconsistent with the non-stream path.Verified: streamed
```json\n{"city":"Tokyo"}\n```withresponse_format={"type":"json_object"}→get_final_completion()content was'```json\n{"city": "Tokyo"}\n```'(leak); non-stream returned'{"city": "Tokyo"}'.Fix
Thread the strip flag from
stream()intoInterfazeStream/AsyncInterfazeStreamand applystrip_json_fencein_State.build(). Scoped to the aggregated result (get_final_completion()) — the live-delta path is intentionally not given a chunk-boundary fence stripper (incrementally-fenced JSON isn't a real usage; buffering a whole-message fence would defeat streaming). Movedstrip_json_fenceinto_stream.py(shared with_chat) to avoid a circular import.This is a pre-existing SDK inconsistency and is deploy-independent: pre-#218 it fixes the current leak; once #218 strips the fence server-side, our strip becomes a harmless no-op on already-bare JSON.
Tests
3 new:
json_objectstream → fence stripped +json.loadsworks; non-json_objectstream with a fenced body → fence preserved (only strip in json_object mode); async json_object → stripped. Suite: 27 passing;ruff+mypy --strictclean.