Skip to content

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

@TaoChenOSU

Description

@TaoChenOSU
Contributor

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.

Activity

added theissue type on Jun 10, 2025
changed the title [-]Bug: OpenAPI plugin function name parsing results in invalid kernel function name[/-] [+]Python: Bug: OpenAPI plugin function name parsing results in invalid kernel function name[/+] on Jun 10, 2025
changed the title [-]Python: Bug: OpenAPI plugin function name parsing results in invalid kernel function name[/-] [+]Bug: OpenAPI plugin function name parsing results in invalid kernel function name[/+] on Jun 10, 2025
sshandilya1991

sshandilya1991 commented on Jun 12, 2025

@sshandilya1991
Contributor

hey @TaoChenOSU / @moonbox3
I surmise this is due to this

I can raise a fix for this - but here is a question:

  • do we want to fail/raise if operationId is not present ? If yes, then is it the right place to fail or we should fail a little before in parsing logic.
  • if we don't want to raise/throw (assuming operationId is not obtained from details object) - the variable operationId would be something like /users_get which is going to fail the regex validation. So, question is to either to make the regex validation flexible or making sure operationId in details exists or maybe something else that I may be missing.

thoughts?

Edit:
I see that anyway we are directly using operation.id in further functions assuming it's there anyway - so, IMO, we should simply have a validation for it & raise if it's not there or probably create one if not there in openapispec(wild thought) ?

moonbox3

moonbox3 commented on Jun 19, 2025

@moonbox3
Collaborator

Hi, @sshandilya1991, yes, we should have validation for it early on and raise if operationId isn't present.

added a commit that references this issue on Jun 24, 2025
16d708e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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

    Participants

    @TaoChenOSU@moonbox3@sshandilya1991@markwallace-microsoft

    Issue actions

      Bug: OpenAPI plugin function name parsing results in invalid kernel function name · Issue #12443 · microsoft/semantic-kernel