Skip to content
GitHubDiscord

Utilities

Helper functions and utilities for normalization, value providers, and parameter injection.


Module: giskard.checks.utils.normalization

Utilities for normalizing strings and data structures using Unicode normalization forms.

normalize_string() str

Normalize a string using a specified Unicode normalization form.

value str Required
String to normalize.
normalization_form Literal["NFC", "NFD", "NFKC", "NFKD"] | None Default: None
Unicode normalization form.
normalize_data() T

Recursively normalize all strings in a dictionary or list.

data T (dict | list) Required
Data structure to normalize.
normalization_form Literal["NFC", "NFD", "NFKC", "NFKD"] | None Default: None
Unicode normalization form.
from giskard.checks.utils.normalization import normalize_string, normalize_data
normalized = normalize_string(
"cafe\u0301", normalization_form="NFC"
) # "cafe" -> "cafe"
data = {"name": "cafe\u0301", "items": ["nai\u0308ve", "re\u0301sume\u0301"]}
normalized_data = normalize_data(data, normalization_form="NFC")
FormDescriptionUse case
NFCCanonical CompositionMost common; combines characters
NFDCanonical DecompositionSeparates base + combining characters
NFKCCompatibility CompositionCombines + converts compatibility chars
NFKDCompatibility DecompositionSeparates + converts compatibility chars

Module: giskard.checks.utils.value_provider

Abstract value provider patterns for static values and callables.

Abstract base class for value providers.

.provide() R

Provide a value. Subclass and implement this method.

Provider for static values.

value R Required

The static value to provide.

from giskard.checks.utils.value_provider import StaticValueProvider
provider = StaticValueProvider(value="hello")
result = await provider.provide() # "hello"

Provider that wraps a callable with parameter injection.

callable Callable Required

Function to call for value.

injection_mapping CallableInjectionMapping Required

Parameter injection configuration.

Provider for generator-based values.

from giskard.checks.utils.value_provider import ValueGeneratorProvider
async def value_generator():
yield "first"
yield "second"
provider = ValueGeneratorProvider.from_mapping(value_generator)

Module: giskard.checks.utils.parameter_injection

Dynamic parameter injection for callables.

Maps parameters to inject into a callable.

.from_callable() CallableInjectionMapping

Create an injection mapping from a callable’s signature.

callable Callable Required
The function to create mapping for.
.inject_parameters() Callable

Inject parameters into a callable, returning a bound callable.

value Callable Required
Callable to inject into.

Configuration for a single parameter injection.

name str Required

Parameter name.

source str Required

Source of the injected value.


Module: giskard.checks.utils.generator

a_generator() AsyncGenerator

Convert a value or generator (sync or async) into an async generator. Useful for normalizing different input types uniformly.

value_or_generator YieldType | SyncOrAsyncGenerator Required
Value or generator to convert.
from giskard.checks.utils.generator import a_generator
# Static value -> yields once
async for value in a_generator("hello"):
print(value)
# Sync generator -> async
def sync_gen():
yield 1
yield 2
async for value in a_generator(sync_gen()):
print(value)