1{2"reasoning":{3"intent_summary":"<30-60字:辨識使用者意圖>",4"key_signals":"<20-40字:抓出使用者請求中的關鍵詞與語意訊號>",5"conclusion":"<30-60字:說明為什麼選 X 或為什麼拒絕匹配>"6},7"selected_tool":"<候選工具名稱,或在拒絕匹配時為 null>",8"signal":"commit | abstain",9"confidence":"high | medium | low"10}
It is designed to run as an independent validator in parallel with a serving LLM that produces actual tool calls. The guardrail's output serves as a reference for downstream arbitration (human review or programmatic logic).
Performance Summary
Metric
L1 base
L2 adapter
L3 +Filter
Format Validity
100.0%
100.0%
100.0%
Tool Accuracy
57.0%
100.0%
100.0%
Signal Accuracy
73.0%
100.0%
100.0%
Confidence Accuracy
48.0%
99.0%
99.0%
False Alarm Rate
0.0%
0.0%
0.0%
Miss Rate
40.9%
0.0%
0.0%
The base Qwen2.5-3B-Instruct achieves 57% tool accuracy and 48% confidence accuracy. After LoRA fine-tuning on 600 synthetic samples (Traditional Chinese), the model reaches 100% tool accuracy and 99% confidence accuracy on the in-distribution holdout. The two-layer post-processing filter (Schema + Provenance) is retained as a safety net for out-of-distribution inputs.
Training Details
Item
Value
Base model
Qwen/Qwen2.5-3B-Instruct
Method
LoRA (r=16, alpha=32, dropout=0.05)
Target modules
q_proj, k_proj, v_proj, o_proj
Training data
600 synthetic samples (Traditional Chinese)
Validation data
100 in-distribution holdout samples
Epochs
3
Batch size
2 × grad_accum 4 (effective 8)
Learning rate
2e-4 (cosine schedule, warmup 5%)
Max length
1024
Hardware
Google Colab T4 (15 GB VRAM, fp16)
Training time
~4.4 hours
Best eval_loss
0.0051
Deployment Notes
Gradio compatibility shim
If you integrate this model into a Gradio app (including HF Spaces), add this monkey-patch before import gradio to avoid ImportError: cannot import name 'HfFolder' from 'huggingface_hub':
python
1# Compat shim: huggingface_hub >= 1.0 removed HfFolder, but gradio (4.x and 5.x) still imports it2import huggingface_hub as _hf_hub
3ifnothasattr(_hf_hub,"HfFolder"):4class_HfFolderShim:5@staticmethod6defget_token():7try:return _hf_hub.get_token()8except Exception:returnNone9@staticmethod10defsave_token(token):11try: _hf_hub.login(token=token)12except Exception:pass13@staticmethod14defdelete_token():15try: _hf_hub.logout()16except Exception:pass17 _hf_hub.HfFolder = _HfFolderShim
1819import gradio as gr # safe now