llm_client: 진짜 JSON 앞에 군더더기 { 한 줄이 붙은 응답 처리 (고객사 실측)

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
byeongwook.choi
2026-09-21 16:54:40 +09:00
co-authored by Claude Fable 5.1
parent d8718c858f
commit c577d5cb93
2 changed files with 48 additions and 0 deletions
+13
View File
@@ -303,3 +303,16 @@ def test_extract_json_dumps_unreadable_content(tmp_path, monkeypatch):
_extract_json("안녕하세요! 반갑습니다.")
dumped = list((tmp_path / "_badjson").glob("*.txt"))
assert len(dumped) == 1 and "안녕하세요" in dumped[0].read_text(encoding="utf-8")
def test_extract_json_skips_stray_opening_brace(tmp_path, monkeypatch):
"""고객사 실측: `{` 한 줄 뒤에 진짜 JSON (Expecting property name enclosed in double quotes: line 2 column 1)."""
from config.settings import settings
monkeypatch.setattr(settings, "data_llm_jobs", tmp_path)
assert _extract_json('{\n{"program": "ZRMEM2016", "business_purpose_ko": "요약"}') == {
"program": "ZRMEM2016", "business_purpose_ko": "요약"}
# 군더더기 { + 값 안 따옴표까지 같이 틀린 경우
assert _extract_json('{\n{"program": "Z1", "x": "a "b" c"}')["x"] == 'a "b" c'
# 서문 + 객체 두 개면 첫 번째 완전한 객체
assert _extract_json('결과:\n{"a": 1}\n{"b": 2}') == {"a": 1}
assert not list((tmp_path / "_badjson").glob("*")) if (tmp_path / "_badjson").exists() else True