Skip to content

Feature request: Handle duplicated/echoed key pattern from Gemini #9

Description

@malloryerik

Note: Everything below from Claude Code. And I'm so thankful for this library; it's great! The weird case I'm sending is from gemini-2.5-flash-lite, which apparently loves to mess up JSON. Is regex right for this fix, as Claude Code suggests? I really don't know... Anyway thanks again.

Feature request: Handle duplicated/echoed key pattern from Gemini

Pattern Description

Gemini sometimes returns malformed JSON with an echoed key inside the value:

{"coach_notes": "coach_notes": "You showed grace under pressure."}
The key "coach_notes" appears twice - once as the actual key, and once echoed at the start of the value.

Expected valid JSON

{"coach_notes": "You showed grace under pressure."}
Current behavior
JsonRemedy returns:


{:error, "Could not repair JSON - all layers processed but validation failed"}
Suggested fix
This pattern can be detected with regex:


~r/^\{"([^"]+)":\s*"\1":\s*"((?:[^"\\]|\\.)*)"\}$/s
Where \1 back-references the first captured key name.

Context
This is a Gemini-specific bug that occurs occasionally with structured output responses. We've seen it with coach_notes but it could happen with any key.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions