def _validate_path_against_schema(
        self, path_parts: List[Union[str, int]], model_class: Type[BaseModel]
    ) -> None:
        """
        Validate that a path corresponds to valid fields in the Pydantic model schema.

        Args:
            path_parts: Parsed path components
            model_class: The Pydantic model class to validate against

        Raises:
            ValueError: If the path contains invalid fields

        """
        if not path_parts:
            return

        current_model = model_class
        current_path = ""

        for i, part in enumerate(path_parts):
            current_path += f"/{part}" if current_path else f"{part}"

            # If part is an integer or '-' (array append), we're dealing with an array index
            if isinstance(part, int) or part == "-":
                continue

            # Check if this field exists in the current model
            if hasattr(current_model, "model_fields"):
                fields = current_model.model_fields
            else:
                # Fallback for older Pydantic versions
                fields = getattr(current_model, "__fields__", {})

            if part not in fields:
                raise ValueError(
                    f"Invalid field '{part}' at path '/{current_path}'. Valid fields are: {list(fields.keys())}"
                )

            # Get the field type for nested validation
            field_info = fields[part]

            # Handle nested models
            if hasattr(field_info, "annotation"):
                field_type = field_info.annotation
            else:
                # Fallback for older Pydantic versions
                field_type = getattr(field_info, "type_", None)

            if field_type:
                # Handle Optional types
                if hasattr(field_type, "__origin__") and field_type.__origin__ is Union:
                    # Extract non-None type from Optional
                    args = getattr(field_type, "__args__", ())
                    field_type = next(
                        (arg for arg in args if arg is not type(None)), field_type
                    )

                # Handle List types
                if hasattr(field_type, "__origin__") and field_type.__origin__ in (
                    list,
                    List,
                ):
                    # For list types, the next part should be an index or '-'
                    if i + 1 < len(path_parts) and (
                        isinstance(path_parts[i + 1], int) or path_parts[i + 1] == "-"
                    ):
                        continue
                    # If we're at the end of the path and it's a list, that's valid too
                    elif i + 1 == len(path_parts):
                        continue

                # If it's a BaseModel subclass, use it for next iteration
                if isinstance(field_type, type) and issubclass(field_type, BaseModel):
                    current_model = field_type
                else:
                    # If we have more path parts but current field is not a model or list, check validity
                    if (
                        i + 1 < len(path_parts)
                        and not isinstance(path_parts[i + 1], int)
                        and path_parts[i + 1] != "-"
                    ):
                        raise ValueError(
                            f"Cannot access nested field '{path_parts[i + 1]}' on non-object field '{part}' of type {field_type}"
                        )

        Validate that a path corresponds to valid fields in the Pydantic model schema.

        Args:
            path_parts: Parsed path components
            model_class: The Pydantic model class to validate against

        Raises:
            ValueError: If the path contains invalid fields

        
llama-index-integrations/tools/llama-index-tools-artifact-editor/llama_index/tools/artifact_editor/base.py