Skip to content
GitHubDiscord

Utilities

Helper functions and utilities for normalization, value providers, and async generator handling.


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 data structure. Dictionaries, lists, tuples, and sets are walked recursively; bare strings are normalized via normalize_string; any other value is returned unchanged.

data T (dict | list | tuple | set | str) 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.injectable

Thin wrappers that let the framework treat a static value and a callable interchangeably. Both wrappers accept either a plain value or a (sync or async) callable, and both inject only the keyword arguments declared in their kwargs_keys set.

Wraps either a static value or a (sync or async) callable that returns a value. Calling the provider with await provider(**kwargs) returns the value, awaiting the callable if needed.

ValueProvider() ValueProvider

Construct a value provider.

value_or_callable ProviderType[..., R] Required
A static value of type R, or a sync/async callable returning R.
kwargs_keys set[str] Required
Names of keyword arguments that may be injected when the provider is called. The constructor inspects the callable’s signature against this set: any non-injected parameter must have a default, otherwise a TypeError is raised.
from giskard.checks.utils.injectable import ValueProvider
# Static value
static_provider = ValueProvider(value_or_callable="hello", kwargs_keys=set())
result = await static_provider() # "hello"
# Callable with injected kwargs
def greet(name: str) -> str:
return f"Hello, {name}!"
callable_provider = ValueProvider(value_or_callable=greet, kwargs_keys={"name"})
result = await callable_provider(name="world") # "Hello, world!"

Wraps either a value or a (sync or async) generator. Internally delegates to a ValueProvider and then routes the result through a_generator, so calling await generator(**kwargs) always yields an AsyncGenerator[R, S].

ValueGenerator() ValueGenerator

Construct a value generator.

value_or_callable GeneratorType[..., R, S] Required
A static value, a callable returning a value, or a callable returning a sync/async generator of R (with send-type S).
kwargs_keys set[str] Required
Names of keyword arguments that may be injected. Same validation rules as ValueProvider.
from giskard.checks.utils.injectable import ValueGenerator
async def items():
yield "first"
yield "second"
gen = ValueGenerator(value_or_callable=items, kwargs_keys=set())
async for value in await gen():
print(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)