Skip to content

Add basic validation function in python#624

Merged
wrenj merged 7 commits intomainfrom
validation
Feb 13, 2026
Merged

Add basic validation function in python#624
wrenj merged 7 commits intomainfrom
validation

Conversation

@wrenj
Copy link
Collaborator

@wrenj wrenj commented Feb 12, 2026

To cover common errors not covered by the json schema

Copy link
Contributor

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

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 introduces a new validation layer for A2UI JSON payloads, which is a great addition to ensure data integrity beyond basic schema validation. The new validation.py module is well-structured and includes checks for component integrity, topology (cycles, orphans), recursion depth, and path syntax. The accompanying test suite in test_validation.py is comprehensive and covers many important edge cases.

My feedback includes a critical point about silent error handling that could lead to validation being skipped, and a suggestion to improve maintainability by refactoring hardcoded values into constants. Overall, this is a solid contribution that significantly improves the robustness of A2UI message processing.

Comment on lines 189 to 191
except Exception:
# If schema traversal fails, return empty map
pass
Copy link
Contributor

Choose a reason for hiding this comment

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

high

Using a broad except Exception: with a pass is dangerous. It will silently swallow any errors that occur during schema parsing (e.g., due to an unexpected schema structure), resulting in an empty ref_map. This effectively disables all component reference validation without any warning, which could allow invalid JSON to pass through. At a minimum, this should log a warning to indicate that reference validation was skipped. A better approach would be to handle more specific exceptions related to key/index errors during dictionary traversal.

Comment on lines 230 to 250
if global_depth > 50:
raise ValueError("Global recursion limit exceeded: Depth > 50")

if isinstance(item, list):
for x in item:
traverse(x, global_depth + 1, func_depth)
return

if isinstance(item, dict):
# Check for path
if PATH in item and isinstance(item[PATH], str):
path = item[PATH]
if not re.fullmatch(JSON_POINTER_PATTERN, path):
raise ValueError(f"Invalid JSON Pointer syntax: '{path}'")

# Check for FunctionCall
is_func = CALL in item and ARGS in item

if is_func:
if func_depth >= 5:
raise ValueError(f"Recursion limit exceeded: {FUNCTION_CALL} depth > 5")
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The recursion depth limits (50 for global, 5 for function calls) are hardcoded as magic numbers. To improve readability and maintainability, it's better to define these as module-level constants (e.g., MAX_GLOBAL_DEPTH = 50, MAX_FUNC_CALL_DEPTH = 5). This makes their purpose clear and allows them to be easily located and modified in one place.

@nan-yu
Copy link
Collaborator

nan-yu commented Feb 13, 2026

The build was failing because of the format check. uv run pyink . would reformat the files.

@wrenj wrenj enabled auto-merge (squash) February 13, 2026 21:33
@wrenj
Copy link
Collaborator Author

wrenj commented Feb 13, 2026

The build was failing because of the format check. uv run pyink . would reformat the files.

done!

Copy link
Collaborator

@nan-yu nan-yu left a comment

Choose a reason for hiding this comment

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

/LGTM

@wrenj wrenj merged commit b1aeb81 into main Feb 13, 2026
9 checks passed
@wrenj wrenj deleted the validation branch February 13, 2026 21:44
@github-project-automation github-project-automation bot moved this from Todo to Done in A2UI Feb 13, 2026
@nan-yu nan-yu mentioned this pull request Feb 23, 2026
8 tasks
lukasmoschitz pushed a commit to CopilotKit/A2UI that referenced this pull request Feb 25, 2026
@nan-yu nan-yu mentioned this pull request Feb 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants