Repository navigation
fix(utils): ignore braces inside strings when extracting nested json (#1401) - #1408
Closed
ExtremeNina wants to merge 1 commit into
Closed
ExtremeNina wants to merge 1 commit into
ExtremeNina wants to merge 1 commit into
Conversation
Contributor
|
此修复已由 #1415 接续并合并到 main,关闭本 PR 以避免重复合并。 原作者 ExtremeNina 的提交作者信息、提交说明及独立提交记录已保留。由于仓库禁用 merge commit,使用 rebase merge 后原提交 补充修复避免将非法或截断 JSON 的内部子对象/数组当作完整回答,保留说明文字、Markdown 包装、字符串内括号及转义字符的提取支持。与最新主分支组合验证的相关测试共 57 项通过,合并后的完整文件树与已验证版本一致。 |
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.
…(#1401)
背景与问题
当大模型生成的 SQL 字符串内部包含
{或}(如LIKE '%{vip}%'、SQL 中的 JSON 模板或正则)时,原有的extract_nested_json因仅使用简单的括号计数栈、未识别字符串内部状态,导致栈计数失衡并返回None,上层误报"SQL answer is not a valid json object"。修改内容
extract_nested_json(backend/common/utils/utils.py):json.JSONDecoder(strict=False).raw_decode流式解析 JSON;\"、\\等)及多行格式;orjson.loads二次校验,确保下游解析兼容性;backend/tests/test_extract_nested_json.py):{、单侧}、成对{}模糊匹配、转义引号、反斜杠路径、Markdown 代码块及前置干扰项等 17 项测试用例。验证情况
uv run pytest tests/test_extract_nested_json.py -v(17 passed);uv run pytest tests/test_data_format.py tests/test_codex_mcp_runtime.py tests/test_connection_pool_manager.py -v(23 passed),无回归。