FnCheck wraps any boolean function into a named check. Use it when the logic
fits in one expression.
from giskard.checks import FnCheck, Scenario
is_short =FnCheck(
fn=lambdatrace:len(trace.last.outputs)<200,
name="response_is_concise",
success_message="Response is concise",
failure_message="Response is too long",
)
scenario =(
Scenario("concise_reply")
.interact(inputs="Summarize in one sentence.",outputs=lambdainputs:my_llm(inputs))
.check(is_short)
)
Output
Thank you for using Giskard open-source! đ˘ đ
Giskard Enterprise adds deeper agent scans, audit reports
with remediation guidance, test review interfaces
for root-cause analysis & human feedback integration,
and team collaboration â with flexible pricing.
Learn more: https://giskard.ai
For anything more complex, define a named function:
@Check.register("contains_keyword") is optional but recommended. It registers the class under a stable string key that is used when serializing and deserializing scenarios and test suites. Without it, serialization falls back to the fully-qualified class name, which breaks if you rename or move the class.
Use resolve(trace, key) to extract values from the trace using dot-notation
paths â the same paths used by Equals, Groundedness, and other built-ins.
from giskard.checks import Check, CheckResult, Trace
from giskard.checks.core.extraction import resolve
from pydantic import Field
classMaxTokens(Check):
key:str=Field(default="trace.last.outputs")
limit:int=Field(default=500)
asyncdefrun(self,trace: Trace)-> CheckResult:
value =resolve(trace,self.key)
token_count =len(str(value).split())
passed = token_count <=self.limit
msg =f"{token_count} tokens ({'ok'if passed elsef'exceeds limit of {self.limit}'})"
BaseLLMCheck handles generator setup and prompt rendering. Override
get_prompt and let the base class call the LLM and parse the
passed: true/false response.
from giskard.checks import BaseLLMCheck
from pydantic import Field
classToneCheck(BaseLLMCheck):
tone:str=Field(
...,description="Expected tone, e.g. 'professional', 'empathetic'"
)
defget_prompt(self)->str:
returnf"""
Evaluate whether the following response has a {self.tone} tone.
Response: {{{{ trace.last.outputs }}}}
Return 'passed: true' if the tone is {self.tone}, 'passed: false' otherwise.
By default BaseLLMCheck expects the LLM to return a JSON object with the shape {"reason": str | None, "passed": bool}. You can change this by overriding output_type (a Pydantic model) and _handle_output. See the BaseLLMCheck API reference for details.
Group related checks into a helper function that returns a list, then pass
them to .check() with the variadic form. Checks run sequentially â the
scenario stops at the first failure, so order matters. Put cheap, fast checks
before expensive LLM-based judges.