Skip to content

Commit

Permalink
fix(json_in_md_parser): improve error messages for JSON parsing failu…
Browse files Browse the repository at this point in the history
…res (#11948)

Signed-off-by: -LAN- <[email protected]>
  • Loading branch information
laipz8200 authored Dec 22, 2024
1 parent a056a9d commit 90f093e
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions api/libs/json_in_md_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def parse_json_markdown(json_string: str) -> dict:
extracted_content = json_string[start_index:end_index].strip()
parsed = json.loads(extracted_content)
else:
raise Exception("Could not find JSON block in the output.")
raise ValueError("could not find json block in the output.")

return parsed

Expand All @@ -36,10 +36,10 @@ def parse_and_check_json_markdown(text: str, expected_keys: list[str]) -> dict:
try:
json_obj = parse_json_markdown(text)
except json.JSONDecodeError as e:
raise OutputParserError(f"Got invalid JSON object. Error: {e}")
raise OutputParserError(f"got invalid json object. error: {e}")
for key in expected_keys:
if key not in json_obj:
raise OutputParserError(
f"Got invalid return object. Expected key `{key}` to be present, but got {json_obj}"
f"got invalid return object. expected key `{key}` to be present, but got {json_obj}"
)
return json_obj

0 comments on commit 90f093e

Please sign in to comment.