Skip to content

Bug: OpenAPI plugin function name parsing results in invalid kernel function name #12443

@TaoChenOSU

Description

@TaoChenOSU

Describe the bug
The fallback mechanism in handling an OpenAPI operation that doesn't have an operation ID may result in invalid kernel function name: https://github.com/microsoft/semantic-kernel/blob/main/python/semantic_kernel/connectors/openapi_plugin/openapi_parser.py#L239

Traceback (most recent call last):
  File "C:\Users\taochen\Project\semantic-kernel\python\semantic_kernel\functions\kernel_function_from_method.py", line 69, in __init__
    metadata = KernelFunctionMetadata(
               ^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\taochen\Project\semantic-kernel\python\.venv\Lib\site-packages\pydantic\main.py", line 253, in __init__
    validated_self = self.__pydantic_validator__.validate_python(data, self_instance=self)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
pydantic_core._pydantic_core.ValidationError: 1 validation error for KernelFunctionMetadata
name
  String should match pattern '^[0-9A-Za-z_-]+$' [type=string_pattern_mismatch, input_value='/anything_patch', input_type=str]
    For further information visit https://errors.pydantic.dev/2.11/v/string_pattern_mismatch

To Reproduce
Steps to reproduce the behavior:

  1. Go to sample: https://github.com/microsoft/semantic-kernel/tree/main/python/samples/concepts/plugins/openapi
  2. Open openapi.yaml
  3. Comment out line 11
  4. Run openapi_client.py

Expected behavior
The plugin is successfully added to the kernel.

Platform

  • Language: Python

Additional context
We should either require the operationId attribute or perform some more meaningful parsing and a more targeted error message.

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingpythonPull requests for the Python Semantic Kernel

Type

Projects

Status

No status

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions