Utilities
Helper functions and utilities for normalization, value providers, and parameter injection.
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 dictionary or list.
data T (dict | list) 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.value_provider
Abstract value provider patterns for static values and callables.
ValueProvider
Section titled âValueProviderâAbstract base class for value providers.
.provide() → R Provide a value. Subclass and implement this method.
StaticValueProvider
Section titled âStaticValueProviderâ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"CallableValueProvider
Section titled âCallableValueProviderâProvider that wraps a callable with parameter injection.
callable Callable Required Function to call for value.
injection_mapping CallableInjectionMapping Required Parameter injection configuration.
ValueGeneratorProvider
Section titled âValueGeneratorProviderâ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)Parameter Injection
Section titled âParameter InjectionâModule: giskard.checks.utils.parameter_injection
Dynamic parameter injection for callables.
CallableInjectionMapping
Section titled âCallableInjectionMappingâMaps parameters to inject into a callable.
.from_callable() → CallableInjectionMapping Create an injection mapping from a callableâs signature.
callable Callable Required .inject_parameters() → Callable Inject parameters into a callable, returning a bound callable.
value Callable Required ParameterInjection
Section titled âParameterInjectionâConfiguration for a single parameter injection.
name str Required Parameter name.
source str Required Source of the injected 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