Evaluate JSON content against expected schemas using structural similarity and LLM judgment
json_schema_reward
function to assess whether models generate JSON content that matches expected
schemas, with options for both structural validation and LLM-based judgment.
messages
: Conversation history with user requests and assistant responsesground_truth
: Optional expected response (not used in schema validation)evaluation_result
: Pre-computed evaluation scores for validationinput_metadata
: Additional context including expected schema and test case descriptionsjson
: Python’s JSON module for JSON parsing and validationtyping
: Python’s typing module for type hints (Any, Dict, List)EvaluationRow
: Data structure containing conversation messages and ground truthdefault_single_turn_rollout_processor
: Default processor for single-turn conversationsevaluation_test
: Decorator for configuring evaluation testsjson_schema_reward
: Function to evaluate JSON content against expected schemas@evaluation_test
decorator to configure our JSON schema evaluation:
input_dataset
: Path to the JSON schema dataset filemodel
: Target model to evaluate (Fireworks Kimi model in this example)mode
: Set to “pointwise” for individual sample evaluationrollout_processor
: Uses default single-turn processor for conversation handlingdataset_adapter
: References our custom adapter functionjson_schema_reward
to compare generated JSON against expected schemajson_schema_reward
function provides comprehensive JSON validation capabilities:
Scenario | Description |
---|---|
Exact schema compliance | JSON that perfectly matches expected structure |
Type consistency | All data types match schema specifications |
Nested object handling | Complex nested structures with proper validation |
Scenario | Description |
---|---|
Missing properties | JSON with some expected fields omitted |
Extra properties | JSON with additional fields not in schema |
Type mismatches | Correct structure but wrong data types |
Scenario | Description |
---|---|
Invalid JSON syntax | Malformed JSON that cannot be parsed |
Missing JSON content | Responses without extractable JSON |
Empty structures | Edge cases with empty objects or arrays |
Scenario | Description |
---|---|
Array validation | JSON arrays with consistent item structures |
Mixed data types | Objects with various primitive and complex types |
Nested arrays | Multi-level nested structures with arrays of objects |