Giskard - Cheatsheet del Framework di Test per ML e LLM
Giskard - Cheatsheet del Framework di Test per ML e LLM
Giskard è un framework di test open-source per applicazioni ML e LLM. La sua caratteristica distintiva è una scansione automatizzata che testa un modello alla ricerca di vulnerabilità — allucinazione, prompt injection, contenuti dannosi, fallimenti di robustezza, bias e perdita di dati — e produce un report che puoi convertire direttamente in una suite di test riutilizzabile. Quel flusso di lavoro scan-then-testify è ciò che lo distingue: non devi sapere in anticipo cosa testare.
Installation
| Method | Command |
|---|---|
| pip | pip install giskard |
| LLM extras | pip install "giskard[llm]" |
| Model key | export OPENAI_API_KEY=... (usato per i rilevatori basati su LLM) |
| Verify | python -c "import giskard; print(giskard.__version__)" |
Wrapping an LLM App
import giskard
import pandas as pd
def predict(df: pd.DataFrame):
return [my_llm_app(q) for q in df["question"]]
model = giskard.Model(
model=predict,
model_type="text_generation",
name="Support Assistant",
description="Answers customer questions using our docs",
feature_names=["question"],
)
dataset = giskard.Dataset(
pd.DataFrame({"question": ["How do I reset my password?"]}),
target=None,
)
| Field | Why it matters |
|---|---|
description | Giskard l”usa per generare probe rilevanti |
model_type | text_generation, classification, regression |
feature_names | Colonne di input |
La description non è cosmetica — lo scanner genera input avversariali specifici del dominio da essa.
Scanning
report = giskard.scan(model, dataset)
report.to_html("scan_report.html")
| Detector | Finds |
|---|---|
| Hallucination | Affermazioni non supportate o incoerenti |
| Prompt injection | Override di istruzioni |
| Harmfulness | Generazione di contenuti non sicuri |
| Robustness | Sensibilità a triviali cambiamenti di input |
| Sensitive disclosure | Perdita di segreti/PII |
| Stereotypes | Bias negli output |
| Performance bias | Accuratezza non uniforme tra slice (tabular/NLP) |
# Scan only specific detector groups
report = giskard.scan(model, dataset, only=["hallucination", "jailbreak"])
Scan → Test Suite
suite = report.generate_test_suite("Support Assistant tests")
suite.run()
Questo è il flusso di lavoro chiave: i risultati diventano test di regressione, quindi un problema risolto rimane risolto e può essere gated in CI.
Custom Tests
from giskard import test, TestResult
@test(name="No refund promises")
def no_refund_promise(model, dataset):
outputs = model.predict(dataset).prediction
bad = [o for o in outputs if "guaranteed refund" in o.lower()]
return TestResult(passed=len(bad) == 0, metric=len(bad))
suite.add_test(no_refund_promise).run()
RAG Evaluation (RAGET)
Giskard include un toolkit di valutazione RAG che genera una serie di domande dalla tua knowledge base e valuta ogni componente della pipeline.
| Component scored | Tells you |
|---|---|
| Generator | La risposta dell”LLM è buona dato il contesto? |
| Retriever | Il recupero ha fatto emergere i chunk giusti? |
| Rewriter | La riscrittura delle query sta aiutando? |
| Router | La query è stata instradata correttamente? |
| Knowledge base | Il materiale di origine è adeguato? |
La valutazione a livello di componente è più attuabile di un singolo numero end-to-end — ti dice quale fase correggere.
Giskard vs Related Tools
| Aspect | Giskard | DeepEval | garak |
|---|---|---|---|
| Core idea | Auto-scan → suite di test | Metriche in stile unit-test | Scanner di probe del modello |
| Scope | ML + LLM + RAG | Valutazioni di app LLM | Vulnerabilità del modello LLM |
| Report | Report di scansione HTML ricco | Output CI/dashboard | Report CLI |
| Best for | Scoperta di problemi sconosciuti | Gating di metriche note | Probing ampio dei modelli |
Si integra con DeepEval per il gating di metriche e Ragas per il punteggio RAG; il vantaggio di Giskard è trovare problemi che non avevi pensato di testare.