Skip to content

LLM occasionally returns malformed JSON for short strings #28

@ddnetters

Description

@ddnetters

Description

The brand style checker occasionally fails to parse LLM responses for certain inputs, particularly short strings like "Submit" or "Execute Operation".

Error Examples

From recent PR validation:

| 26 | `Submit` | Failed to parse LLM response: Unexpected token ',', ...""Continue", or "Get "... is not valid JSON |
| 29 | `Execute Operation` | Failed to parse LLM response: Expected ',' or '}' after property value in JSON at position 161 |
| 36 | `Submit` | Failed to parse LLM response: Unexpected token ',', ...""Continue", or "Get "... is not valid JSON |

Context

  • Model: openai:anthropic/claude-3.5-haiku via OpenRouter
  • These errors occur intermittently for short, simple strings
  • The LLM appears to be generating suggestions inline that break the JSON structure

Possible Causes

  1. Short strings may cause the LLM to provide alternative suggestions that aren't properly formatted
  2. The LLM might be including examples like "Continue", or "Get Started" directly in the JSON value, breaking the structure

Suggested Fixes

  1. Add retry logic for malformed JSON responses
  2. Improve the system prompt to more strictly enforce JSON output format
  3. Add post-processing to sanitize/fix common JSON issues before parsing
  4. Consider using structured output (if supported by the provider)

Reproduction

Run the stringly-typed action on a file containing short button labels like:

const buttons = {
  submit: "Submit",
  execute: "Execute Operation"
};

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