skillnet-ai evaluate fails on non-strict JSON outputs (no fallback / repair mechanism)
Description
When using skillnet_ai.evaluator.evaluate with GLM-5 (OpenAI-compatible endpoint), the evaluation frequently fails with:
JSONDecodeError: Expecting value: line 1 column 1 (char 0)
The error occurs at:
return json.loads(raw_response)
This indicates that the LLM output (raw_response) is not a valid JSON string.
Observed Behavior
The evaluator invokes the model with:
response_format={"type": "json_object"}
However, when using GLM-5:
- The response is sometimes empty
- Or not strictly JSON
- Or includes extra text / markdown formatting
Examples of problematic outputs:
""(empty response)"The result looks correct."-
{"score": 1,} {'score': 1}(invalid JSON format)
Because the current implementation directly does:
json.loads(raw_response)
any deviation causes the evaluation to fail.
Root Cause
The current implementation assumes:
LLM output → (optional postprocess) → json.loads
But this assumption does not hold for GLM-5 and other OpenAI-compatible providers:
response_formatis not strictly enforced- Output may be non-deterministic
- Output may be non-JSON or partially valid JSON
Expected Behavior
The evaluator should be robust to:
- Slightly malformed JSON
- Markdown-wrapped JSON
- Non-strict outputs from OpenAI-compatible providers
Suggested Fix
Introduce a robust multi-stage parsing pipeline:
1. Empty response check
cleaned = (raw_response or "").strip()
if not cleaned:
raise ValueError("LLM returned empty response")
2. Lightweight post-processing
- Strip whitespace
- Remove markdown fences if present
3. Standard JSON parsing
try:
result = json.loads(cleaned)
4. Fallback: JSON repair (recommended)
from json_repair import repair_json
try:
result = json.loads(cleaned)
except json.JSONDecodeError:
repaired = repair_json(cleaned)
result = json.loads(repaired)
5. Add logging for debugging
logger.warning(
"JSON parsing failed, attempting repair. raw_response=%r",
cleaned
)
Why This Matters
- GLM-5 and many OpenAI-compatible models do not strictly follow
response_format - Current implementation is too fragile for real-world usage
- Evaluation pipeline should not fail due to minor formatting issues
- This is especially critical for:
- Agent systems
- Skill validation pipelines
- Automated evaluation workflows
Additional Suggestion (Optional)
Consider reinforcing the prompt with:
Return ONLY a valid JSON object. Do not include markdown, explanations, or extra text.
Environment
- skillnet-ai: latest main
- Python: 3.12
- Model: GLM-5 (OpenAI-compatible API)
Summary
The evaluator assumes strict JSON output, which does not hold for GLM-5.
Adding a repair-based fallback and basic validation would significantly improve robustness.
Thank you for your feedback. I have added json_repair to the evaluator, and I hope it can solve your problem.
Hi, do you have any more questions?