Skip to content

fix(checks): accept parsed string JSON values#2512

Closed
harsh21234i wants to merge 4 commits into
Giskard-AI:mainfrom
harsh21234i:fix/json-valid-parsed-string
Closed

fix(checks): accept parsed string JSON values#2512
harsh21234i wants to merge 4 commits into
Giskard-AI:mainfrom
harsh21234i:fix/json-valid-parsed-string

Conversation

@harsh21234i

Copy link
Copy Markdown
Contributor

Closes #2511

Summary

  • allow JsonValid to accept non-empty plain Python strings as already parsed JSON scalar values
  • keep parsing serialized JSON-looking strings such as objects, arrays, quoted strings, numbers, booleans, and null
  • keep empty strings and malformed JSON-looking strings failing as invalid JSON
  • add coverage for plain string outputs and schema validation against plain strings

Testing

  • uv run --no-sync -m pytest -q libs/giskard-checks/tests/builtin/test_json_valid.py
  • uv run --no-sync ruff check libs/giskard-checks/src/giskard/checks/builtin/json_valid.py libs/giskard-checks/tests/builtin/test_json_valid.py

Verification: 23 passed, ruff passed.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request updates the JSON validation logic to accept plain strings as valid inputs instead of attempting to parse them as JSON and failing. It introduces a helper method _looks_like_serialized_json to identify if a string is serialized JSON. The reviewer provided critical feedback regarding potential bugs in this helper: whitespace-only strings can bypass the empty string check, and the prefix-matching logic is too loose, which would incorrectly classify plain strings starting with JSON-like prefixes (e.g., "truth", "nullify") as serialized JSON and cause parsing errors. Robust code suggestions were provided to address both issues.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread libs/giskard-checks/src/giskard/checks/builtin/json_valid.py Outdated
Comment thread libs/giskard-checks/src/giskard/checks/builtin/json_valid.py Outdated
@harsh21234i

Copy link
Copy Markdown
Contributor Author

hey @kevinmessiaen @davidberenstein1957 can someone look into this?

@kevinmessiaen

Copy link
Copy Markdown
Member

Fixed by #2575

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

JsonValid rejects already parsed string values

2 participants