This repository was archived by the owner on Sep 3, 2025. It is now read-only.
fix(ai): allowing whitespace between escape and json markdown#6106
Closed
whitdog47 wants to merge 4 commits into
Closed
fix(ai): allowing whitespace between escape and json markdown#6106whitdog47 wants to merge 4 commits into
whitdog47 wants to merge 4 commits into
Conversation
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Signed-off-by: David Whittaker <84562015+whitdog47@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR switches JSON cleanup from manual string operations to a regex-based helper that tolerates extra whitespace around Markdown fences.
- Added
clean_json_markdownwith a single regex to strip code fences and optional language specifiers. - Replaced inline fence-stripping logic in
generate_case_signal_summaryandget_tag_recommendationswith the new helper.
Comments suppressed due to low confidence (2)
src/dispatch/ai/service.py:105
- Add unit tests for
clean_json_markdownto verify it correctly handles various whitespace scenarios, optional language tags, and escaped newline sequences.
def clean_json_markdown(json_string: str) -> str:
src/dispatch/ai/service.py:567
- The previous logic also replaced escaped newlines and flattened whitespace before validation. Ensure
model_validate_jsoncan handle raw output without those steps or reintroduce necessary newline/whitespace cleanup.
return TagRecommendationResponse.model_validate_json(clean_json_markdown(result))
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
This PR enhances the JSON cleanup logic by switching from simple string replaces to a regex-based approach that tolerates whitespace around Markdown code fences.