Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python: Content Filter Exception not happening on Function Invoke #10011

Open
afrancoc2000 opened this issue Dec 18, 2024 · 0 comments
Open

Python: Content Filter Exception not happening on Function Invoke #10011

afrancoc2000 opened this issue Dec 18, 2024 · 0 comments
Labels
bug Something isn't working python Pull requests for the Python Semantic Kernel triage

Comments

@afrancoc2000
Copy link

Describe the bug
I need to run a prompt I have in a jinja template and check it for filtered content by catching the exception in case it fails but when I run kernel.invoke I only receive KernelInvokeException instead of a ContentFilterAIException.

To Reproduce
Steps to reproduce the behavior:

This is my code:

self.kernel.add_service(AzureChatCompletion())
prompt = self.jinja2.get_prompt_string(file)
self.kernel.add_function(
    prompt=prompt,
    function_name=service_name,
    plugin_name=service_name,
    template_format="jinja2"
)
try:
    result = await self.kernel.invoke(function_name=service_id, plugin_name=service_id, **params)
except ContentFilterAIException as ex:
    self.logger.error('Content filter result', ex.content_filter_result)
    raise Exception(e) from e
except KernelInvokeException as ex:
    self.logger.exception(f"Kernel invoke exception: {ex.__cause__}")
    raise Exception(ex) from ex
except Exception as e:
    self.logger.exception(f"Error getting chat completion response: {e.__cause__}")
    raise Exception(e)

I get KernelInvokeException instead of ContentFilterAIException.

Expected behavior
I need the ContentFilterAIException to be able to handle the error properly.

Platform

  • OS: Windows
  • IDE: VS Code
  • Language: Python
  • Source: semantic-kernel 1.17.0

Additional context
I tried using this code #4802 but is not valid any more.

@afrancoc2000 afrancoc2000 added the bug Something isn't working label Dec 18, 2024
@markwallace-microsoft markwallace-microsoft added python Pull requests for the Python Semantic Kernel triage labels Dec 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working python Pull requests for the Python Semantic Kernel triage
Projects
None yet
Development

No branches or pull requests

2 participants