Glossary

Harness

LLM client input 與 LLM output 之間的程式碼 / script 層,透過多道處理機制確保輸出的正確性與可靠性。

功能層說明實作 / 工具
輸入過濾 Input Filtering送入 LLM 前清除不合法字元、敏感詞或超長內容regex、tokenizer 截斷
參數校驗 Parameter Validation驗證呼叫參數格式是否正確(型別、範圍、必填欄位)Pydantic model
機械攔截 Guard / Interception二元決策:阻擋整個請求或回應(flow halt);過濾是改資料後繼續,攔截是直接拒絕NeMo Guardrails、Guardrails AI、LlamaGuard、OpenAI Moderation API
格式清洗 Format Cleaning清理 / 正規化 LLM 輸出(去除多餘空白、修正 JSON 格式等)自定義 parser、json.loads + 修復
輸出過濾 Output Filtering過濾不符條件的輸出(格式錯誤、包含禁止詞等)regex、Guardrails AI output validator
錯誤重試 Error Retry偵測錯誤或不合格輸出後自動重試,直到取得正確結果Instructor(內建 schema + auto-retry loop)

InstructorGuardrails AI 實務上將 Guard、Validation、Retry 整合為單一 library,不需逐層自建。

  flowchart TD
    A[LLM Client Input] --> B[輸入過濾 Input Filtering]
    B --> C[參數校驗 Parameter Validation]
    C --> D[機械攔截 Guard / Interception]
    D --> E[[LLM]]
    E --> F[格式清洗 Format Cleaning]
    F --> G[輸出過濾 Output Filtering]
    G --> H{合格?}
    H -- Yes --> I[LLM Output 正確結果]
    H -- No --> J[錯誤重試 Error Retry]
    J --> E