Skip to content

refactor(python): update validation logic to support mixed catalogs - #2398

Open
nan-yu wants to merge 14 commits into
v1_0_firing_python_adaptersfrom
v1_0_firing_python_validation
Open

refactor(python): update validation logic to support mixed catalogs#2398
nan-yu wants to merge 14 commits into
v1_0_firing_python_adaptersfrom
v1_0_firing_python_validation

Conversation

@nan-yu

@nan-yu nan-yu commented Aug 25, 2026

Copy link
Copy Markdown
Collaborator
  • Update validation logic to support mixed catalogs
  • Consolidates schema validation into PayloadValidator and surface topology validation into SurfaceComponentsModel, removing monolithic A2uiValidator.

Stacked on top of #2379.

TAG=agy
CONV=707c9b6b-b2da-4940-ba6e-67f0b4f1d563

@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 consolidates and refactors the validation logic across the repository, migrating core validation components to a2ui_core and removing the deprecated validator.py. While the restructuring is beneficial, there are critical issues that must be resolved before merging: unresolved git merge conflict markers exist in base.py within both the imports and the operation extraction logic. Additionally, there is redundant validation in base.py due to recursive calls inside a loop, and a potential TypeError crash in composition_validator.py if comp is not verified as a dictionary.

I am having trouble creating individual review comments. Click here to see my feedback.

python/a2ui_core/src/a2ui/core/processing/adapters/base.py (17-23)

critical

Unresolved git merge conflict markers found in the imports section. Please resolve the conflict and clean up the markers.

from typing import Any, Dict, List, Optional, Set, Union
from pydantic import ValidationError

python/a2ui_core/src/a2ui/core/processing/adapters/base.py (227-256)

critical

Unresolved git merge conflict markers found in the operation extraction logic. Please resolve the conflict by choosing the correct implementation branch and consistently using raw_payload (which is already converted to a dictionary).

            ver_str = (
                self.version.value
                if hasattr(self.version, "value")
                else str(self.version)
            )
            if ver_str != "v0.8":
                if "version" not in raw_payload:
                    raise A2uiValidationError(
                        f"Invalid {self.version} message: messages.0.version: 'version'"
                        " is a required property"
                    )
                if raw_payload["version"] != ver_str:
                    raise A2uiValidationError(
                        f"Invalid {self.version} message: messages.0.version: Input"
                        f" should be '{ver_str}'"
                    )

            prepared_msg = self.prepare_payload_for_validation(raw_payload)
            try:
                self.schema.model_validate({"messages": [prepared_msg]})
            except ValidationError as e:
                details = self._format_validation_errors(e, [raw_payload])
                summary = "; ".join(f"{d.path}: {d.message}" for d in details)
                raise A2uiValidationError(f"Invalid {self.version} message: {summary}")

            return self._extract_operations_for_action(action, raw_payload)

python/a2ui_core/src/a2ui/core/processing/adapters/base.py (206-208)

medium

The loop calls self._extract_single_action(item) to validate each item in the list. However, when self.extract_operations(item) is called recursively, it executes _extract_single_action again on the same items. This causes redundant validation and duplicate execution of _get_surface_id. Consider refactoring to perform this validation only once per payload.

References
  1. Avoid calling recursive payload traversal functions inside loops over messages to prevent redundant traversals and O(N^2) complexity. Run the traversal once per payload instead.

python/a2ui_core/src/a2ui/core/validation/composition_validator.py (42-44)

medium

Ensure comp is a dictionary before calling .get() or iterating over its items in validate_composition_constraints to prevent potential TypeError or AttributeError crashes if invalid payloads are passed.

    for comp in new_components:
        if not isinstance(comp, dict):
            continue
        c_id = comp.get("id")
        c_type = comp.get("component")
References
  1. When validation checks or function arguments can be represented as either a dictionary (named) or a list (positional), always verify the type (e.g., using isinstance(args, dict)) before performing key-based lookups or assignments to prevent TypeError crashes.

@nan-yu
nan-yu force-pushed the v1_0_firing_python_adapters branch from e181cd2 to 53554bf Compare August 27, 2026 17:38
nan-yu added 5 commits August 27, 2026 17:38
Consolidates schema validation into CatalogSchemaValidator and surface graph validation into SurfaceComponentsModel. Removes monolithic A2uiValidator.

TAG=agy
CONV=707c9b6b-b2da-4940-ba6e-67f0b4f1d563
TAG=agy
CONV=707c9b6b-b2da-4940-ba6e-67f0b4f1d563
…, and generic model types

- Simplify MessageProcessor.process_messages to resolve version adapters directly via VersionAdapterFactory.resolve_from_payload
- Consolidate component validation into PayloadValidator and SurfaceComponentsModel.validate_components_update
- Update SurfaceModel, SurfaceGroupModel, DataContext, and NodeGraph to bind TComponent and TFunction generics with PEP 696 defaults
- Add tests and update conformance suites
@nan-yu
nan-yu force-pushed the v1_0_firing_python_validation branch from 4ebea53 to d6df665 Compare August 27, 2026 17:38
@nan-yu nan-yu changed the title refactor(python): consolidate validation logic into CatalogSchemaValidator and SurfaceComponentsModel refactor(python): update validation logic to support mixed catalogs Aug 27, 2026
@nan-yu
nan-yu requested a review from gspencergoog August 27, 2026 18:59
Comment thread eval/a2ui_eval/scorers.py Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant