Utilities
Helper functions and utilities for normalization, value providers, and async generator handling.
Normalization
Section titled “Normalization”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 normalization_form Literal["NFC", "NFD", "NFKC", "NFKD"] | None Default: None 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 normalization_form Literal["NFC", "NFD", "NFKC", "NFKD"] | None Default: None 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")Normalization forms
Section titled “Normalization forms”| Form | Description | Use case |
|---|---|---|
NFC | Canonical Composition | Most common; combines characters |
NFD | Canonical Decomposition | Separates base + combining characters |
NFKC | Compatibility Composition | Combines + converts compatibility chars |
NFKD | Compatibility Decomposition | Separates + converts compatibility chars |
Value Providers
Section titled “Value Providers”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.
ValueProvider
Section titled “ValueProvider”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 R, or a sync/async callable returning R. kwargs_keys set[str] Required TypeError is raised. from giskard.checks.utils.injectable import ValueProvider
# Static valuestatic_provider = ValueProvider(value_or_callable="hello", kwargs_keys=set())result = await static_provider() # "hello"
# Callable with injected kwargsdef 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!"ValueGenerator
Section titled “ValueGenerator”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 R (with send-type S). kwargs_keys set[str] Required 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)Generator Utilities
Section titled “Generator Utilities”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 from giskard.checks.utils.generator import a_generator
# Static value -> yields onceasync for value in a_generator("hello"): print(value)
# Sync generator -> asyncdef sync_gen(): yield 1 yield 2
async for value in a_generator(sync_gen()): print(value)See also
Section titled “See also”- Core API — Core types and base classes
- Built-in Checks — Checks using normalization
- Generators — Input generators