Skip to content

fix(variables): accept JSON string and empty input for json_schema#165

Merged
WH-2099 merged 3 commits into
langgenius:mainfrom
shiyuanfang2nd:fix/variable-entity-json-schema-string
Jun 2, 2026
Merged

fix(variables): accept JSON string and empty input for json_schema#165
WH-2099 merged 3 commits into
langgenius:mainfrom
shiyuanfang2nd:fix/variable-entity-json-schema-string

Conversation

@shiyuanfang2nd
Copy link
Copy Markdown
Contributor

@shiyuanfang2nd shiyuanfang2nd commented May 29, 2026

Important

  1. Make sure you have read our contribution guidelines
  2. Search existing issues and pull requests to confirm this change is not a duplicate
  3. Open or identify the issue this pull request resolves or advances
  4. Use a Conventional Commits title for this pull request, and mark breaking changes with !
  5. Remember that the pull request title will become the squash merge commit message
  6. If CLA Assistant prompts you, sign CLA.md in the pull request conversation

Related Issue

Closes #164

Summary

VariableEntity.json_schema previously only accepted dict | None. However:

  • The frontend code editor persists the schema as raw JSON text, so the
    backend receives a string and validation fails.
  • "Clear schema" on the frontend sends "" instead of dropping the field,
    which also fails validation even though the user intent is "no schema".

Changes

  • validate_json_schema is switched to mode="before" so it can pre-process
    the raw input.
  • Accept a JSON string and parse it into a dict; raise a clear ValueError
    when the string is not valid JSON.
  • Treat None and "" uniformly as "no schema" and return None.
  • Reject non-dict / non-string inputs with an explicit error message.
  • Existing Draft7Validator.check_schema(...) semantic validation is kept.

Tests

Adds tests/variables/test_input_entities.py covering:

  • valid dict input
  • valid JSON string input (mirrors the frontend payload)
  • None input → None
  • "" input → None
  • malformed JSON string → ValidationError
  • non-object / non-string input (e.g. 123) → ValidationError
  • semantically invalid schema, both as dict and as string → ValidationError

No public API or behavior is broken for callers that were already passing
dict | None.

Checklist

  • This pull request links the issue it resolves or advances
  • This pull request title follows Conventional Commits, and any breaking change is marked with !
  • If CLA Assistant prompted me, I signed CLA.md in the pull request conversation

VariableEntity.json_schema previously only accepted dict/None, but the frontend code editor persists the schema as raw JSON text, and clearing the schema sends an empty string instead of dropping the field. Both cases triggered validation errors.

This change switches validate_json_schema to mode="before" so it can: parse JSON strings, treat None/"" as "no schema", and reject non-object inputs with a clear message. Adds tests covering dict / JSON string / empty / invalid JSON / non-object / semantically invalid schema cases.

Refs langgenius#164
@dosubot dosubot Bot added the size:S This PR changes 10-29 lines, ignoring generated files. label May 29, 2026
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 29, 2026

All contributors on this pull request have signed the CLA.
Posted by the CLA Assistant Lite bot.

@shiyuanfang2nd
Copy link
Copy Markdown
Contributor Author

I have read the CLA Document and I hereby sign the CLA

@WH-2099 WH-2099 self-assigned this May 30, 2026
Copy link
Copy Markdown
Member

@WH-2099 WH-2099 left a comment

Choose a reason for hiding this comment

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

Reviewed locally; no blocking issues found.

@dosubot dosubot Bot added the lgtm This PR has been approved by a maintainer label Jun 2, 2026
@WH-2099 WH-2099 enabled auto-merge (squash) June 2, 2026 11:15
@WH-2099 WH-2099 merged commit bfe73c1 into langgenius:main Jun 2, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

lgtm This PR has been approved by a maintainer size:S This PR changes 10-29 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

VariableEntity rejects json_schema input that is a JSON string or empty string

2 participants