Skip to content

Conversation

@nshkrdotcom
Copy link
Owner

Summary

Problem

When JSON content was followed by trailing text (e.g., [{...}]\n1 Volume(s) created), the Layer 1 content cleaning was not removing the trailing wrapper text. This occurred because the should_extract_from_prose? function only checked for content that doesn't start with { or [.

Solution

Implemented a dedicated remove_trailing_wrapper_text/1 function that:

  1. Detects when input starts with a JSON structure ({ or [)
  2. Uses the existing find_balanced_end/3 function to find where the JSON ends
  3. Checks if there's non-whitespace content after the JSON
  4. Extracts only the JSON portion if trailing content exists

Test Results

  • New test case passes ✅
  • All 452 existing tests continue to pass ✅
  • No Dialyzer type warnings ✅
  • Code formatted with mix format

Example

# Before fix:
JsonRemedy.repair_to_string("[{\"id\": 1}]\n1 Volume(s) created")
# => {:error, "Could not repair JSON - all layers processed but validation failed"}

# After fix:
JsonRemedy.repair_to_string("[{\"id\": 1}]\n1 Volume(s) created")
# => {:ok, "[{\"id\":1}]"}

🤖 Generated with Claude Code

Co-Authored-By: Claude [email protected]

nshkrdotcom and others added 2 commits July 4, 2025 18:42
This commit addresses GitHub issue #1 where JSON followed by wrapper text
was not being properly cleaned by the content cleaning layer.

Changes:
- Added remove_trailing_wrapper_text/1 function to detect and remove text
  following valid JSON structures
- Updated extract_json_content_internal/2 to call the new function as a
  final extraction step
- Added test case specifically for the reported issue with JSON arrays
  followed by status messages

The fix ensures that when JSON content is extracted, any trailing
non-JSON text (like "1 Volume(s) created") is properly removed,
returning only the valid JSON structure.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
- Updated version in mix.exs from 0.1.2 to 0.1.3
- Added changelog entry for the trailing wrapper text fix

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
@nshkrdotcom nshkrdotcom merged commit 0493013 into main Jul 5, 2025
1 check passed
@nshkrdotcom nshkrdotcom deleted the fix-issue-1-trailing-wrapper-text branch July 5, 2025 04:46
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.

wrapper text following JSON block not recognized

2 participants