MCPcopy Create free account
hub / github.com/Emmimal/control-layer / _check_json

Method _check_json

control_layer.py:482–503  ·  view source on GitHub ↗
(
        self, response: str, required_keys: List[str]
    )

Source from the content-addressed store, hash-verified

480 return ValidationResult(passed=True, score=score)
481
482 def _check_json(
483 self, response: str, required_keys: List[str]
484 ) -> ValidationResult:
485 try:
486 cleaned = re.sub(r"```(?:json)?|```", "", response).strip()
487 data = json.loads(cleaned)
488 for key in required_keys:
489 if key not in data:
490 return ValidationResult(
491 passed=False,
492 failure_mode=FailureMode.SCHEMA_VIOLATION,
493 message=f"Missing required key: '{key}'",
494 score=0.0,
495 )
496 return ValidationResult(passed=True, score=1.0)
497 except json.JSONDecodeError as exc:
498 return ValidationResult(
499 passed=False,
500 failure_mode=FailureMode.SCHEMA_VIOLATION,
501 message=f"Invalid JSON: {exc}",
502 score=0.0,
503 )
504
505 def _quality_score(self, response: str, schema: ResponseSchema) -> float:
506 if not schema.must_contain:

Callers 1

validateMethod · 0.95

Calls 1

ValidationResultClass · 0.85

Tested by

no test coverage detected