Filter LLM Requests and Responses
6 Semantic Kernel samples for request/response filtering, content moderation, function invocation hooks, and retry logic.
Why it matters
Enhance your AI applications by implementing sophisticated filtering for both incoming requests and outgoing responses. This asset provides hooks for content moderation and custom function invocation logic.
Outcomes
What it gets done
Implement content moderation for LLM interactions.
Add custom logic to function calls.
Filter and transform LLM requests and responses.
Handle streaming responses with filters.
Install
Add it to your toolbox
Run in your project directory:
curl -fsSL https://spark.entire.vc/get/sk-concept-filtering | bash Overview
Semantic Kernel - Filtering
Six Semantic Kernel Python samples for request/response filtering, content moderation, function invocation hooks, and retry-on-failure strategies. Use when an agent needs moderation, function-call guardrails, or retry resilience; skip for simple unfiltered chat completion.
What it does
This is a set of 6 Semantic Kernel Python concept samples covering filtering and hooks: filtering automatic function invocations (auto_function_invoke_filters.py), filtering function invocations generally and in streaming mode (function_invocation_filters.py, function_invocation_filters_stream.py), filtering prompts before they reach the model (prompt_filters.py), and retry strategies - retrying with a different model on failure (retry_with_different_model.py) or retrying using filters (retry_with_filters.py).
When to use - and when NOT to
Use these samples when you need to intercept or moderate what goes into or comes out of the model - content moderation on prompts, guarding which functions an agent is allowed to auto-invoke, or building resilience by retrying with a fallback model or filtered inputs after a failure.
Not needed for simple, unfiltered chat completion use cases - filtering and invocation hooks add a layer of control that's only worth the complexity when you actually need moderation, function-call guardrails, or retry resilience.
Inputs and outputs
Inputs: prompts, function invocation requests, or streaming function calls to be filtered; failure conditions triggering a retry.
Outputs: filtered/moderated prompts or function invocations, and retried completions using either a different model or filtered inputs after an initial failure.
Integrations
Microsoft Semantic Kernel (Python) filtering and function-invocation hook APIs.
Who it's for
Developers who need content moderation, function-call guardrails, or retry resilience built into a Semantic Kernel agent's request/response pipeline.
Source README
Request and response filtering, content moderation, function invocation hooks
Examples (6 files):
auto_function_invoke_filters.pyfunction_invocation_filters.pyfunction_invocation_filters_stream.pyprompt_filters.pyretry_with_different_model.pyretry_with_filters.py
FAQ
Common questions
Discussion
Questions & comments · 0
Sign In Sign in to leave a comment.