Skip to content

fix: use strict=False for JSON parsing of tool calls and session data#1460

Open
Br1an67 wants to merge 1 commit intoMoonshotAI:mainfrom
Br1an67:fix/json-control-chars
Open

fix: use strict=False for JSON parsing of tool calls and session data#1460
Br1an67 wants to merge 1 commit intoMoonshotAI:mainfrom
Br1an67:fix/json-control-chars

Conversation

@Br1an67
Copy link

@Br1an67 Br1an67 commented Mar 17, 2026

Problem

LLM responses sometimes contain raw control characters (newlines, tabs) inside JSON string values in tool call arguments. With the default strict=True, json.loads() rejects these, causing:

  1. Tool call execution failures
  2. Corrupted context.jsonl lines that prevent session restoration

Fix

Use json.loads(..., strict=False) in all critical JSON parsing paths:

  • soul/toolset.py — tool call argument parsing
  • soul/context.py — session restore and checkpoint revert
  • tools/__init__.py — tool argument extraction for display
  • ui/shell/debug.py — debug tool call formatting

Testing

Verified that json.loads('{"key": "value\nwith newline"}', strict=False) correctly parses control characters that would fail with strict=True.

Fixes #1378


Open with Devin

Copy link
Contributor

@devin-ai-integration devin-ai-integration bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no potential bugs to report.

View in Devin Review to see 2 additional findings.

Open in Devin Review

LLM responses sometimes contain raw control characters (newlines,
tabs) inside JSON string values in tool call arguments. With the
default strict=True, json.loads() rejects these, causing tool call
failures and corrupting the session context file so it can never
be restored.

Use strict=False in all critical JSON parsing paths:
- Tool call argument parsing (toolset.py)
- Session context restore and checkpoint revert (context.py)
- Tool argument extraction for display (tools/__init__.py)
- Debug tool call formatting (debug.py)

Fixes MoonshotAI#1378
@Br1an67 Br1an67 force-pushed the fix/json-control-chars branch from efc6868 to fcb799c Compare March 17, 2026 07:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

JSON parsing error when tool call arguments contain control characters

1 participant