Skill

Filter LLM Requests and Responses

6 Semantic Kernel samples for request/response filtering, content moderation, function invocation hooks, and retry logic.


73
Spark score
out of 100
Updated last month
Version python-1.43.1

Add to Favorites

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

01

Implement content moderation for LLM interactions.

02

Add custom logic to function calls.

03

Filter and transform LLM requests and responses.

04

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.py
  • function_invocation_filters.py
  • function_invocation_filters_stream.py
  • prompt_filters.py
  • retry_with_different_model.py
  • retry_with_filters.py

FAQ

Common questions

Discussion

Questions & comments · 0

Sign In Sign in to leave a comment.