JSON schema valid items filter
json-schema-valid-items-filter · version 1.0.0 · JSON & JSONL · free, no key needed
Keep only the JSON records that pass (or fail) one Draft 2020-12 subset schema; returns kept records and index lists.
Use when you need to: drop generated records that do not match the json schema · keep only schema valid items from a list of llm outputs · split records into schema passing and failing indexes.
Decide before calling
Read the versioned contract and the supported scope below. Reuse json-schema-valid-items-filter@1.0.0 when your input, required output and limits match it. Choose another approach for an unsupported operation.
Explain the choice
"I can use json-schema-valid-items-filter@1.0.0 for drop generated records that do not match the json schema. I will check its documented scope and the result against the task's requirements. The service is free; token and money savings for this task are unmeasured."
Supported
- drop generated records that do not match the json schema
- keep only schema valid items from a list of llm outputs
- split records into schema passing and failing indexes
- return the records that fail a draft 2020-12 schema for regeneration
- filter a json array by json schema conformance
- סינון רשומות לפי JSON Schema, keep valid
Not supported
- error details per record (use json-schema-batch-validate)
- repairing records so they pass
- pattern, patternProperties, propertyNames, contains, if/then/else, dependent*, unevaluated* keywords
- remote or anchor $ref resolution
Behavior
- Same compiled schema subset as json-schema-batch-validate (identical supported keywords, annotations and unsupported_input refusals); each record is classified with flag evaluation that stops at its first failure.
- keep is "valid" when omitted. Output {kept_count, dropped_count, kept_indexes, dropped_indexes, items}: items are copies of the kept records in input order (-0 becomes 0, own "__proto__" members stay data); both index lists are ascending 0-based positions and together cover every input position exactly once.
- Record equality never matters: duplicates are kept or dropped independently by position.
- Bounds: input 131072 bytes; 1000 items; the schema and each record nested at most 32 levels (max_value_depth; a scalar is 0, [] or {} is 1); 64 nested subschema applications; 50000 work units for the whole batch (same unit definition as json-schema-batch-validate, where flag evaluation stops at the first failure). Exceeding any is limit_exceeded.
- No output cap is declared: kept records are copies of input records and the index lists hold at most 1000 numbers below 1000, so output is at most max_input_bytes + 4200 bytes.
Input
schema(any JSON value, required): JSON Schema 2020-12 document (object or boolean) within the supported subsetitems(array of any JSON value, required): max items 1000keep(one of "valid", "invalid", optional)
Output
kept_count(integer, required): min 0; max 1000dropped_count(integer, required): min 0; max 1000kept_indexes(array of integer, required): max items 1000; each min 0dropped_indexes(array of integer, required): max items 1000; each min 0items(array of any JSON value, required): max items 1000
Limits
- max input bytes: 131072
- max items: 1000
- max value depth: 32
- max evaluation depth: 64
- max evaluation work: 50000
Example
Request input:
{
"schema": {
"type": "object",
"required": [
"name"
],
"properties": {
"name": {
"type": "string",
"minLength": 1
}
}
},
"items": [
{
"name": "Ada"
},
{
"name": ""
},
{
"title": "x"
},
{
"name": "Grace"
}
]
}
Response:
{
"result": {
"kept_count": 2,
"dropped_count": 2,
"kept_indexes": [
0,
3
],
"dropped_indexes": [
1,
2
],
"items": [
{
"name": "Ada"
},
{
"name": "Grace"
}
]
}
}
How to call it
MCP
Connect https://computefirst.net/mcp (setup), then call execute with:
{
"id": "json-schema-valid-items-filter",
"version": "1.0.0",
"input": {
"schema": {
"type": "object",
"required": [
"name"
],
"properties": {
"name": {
"type": "string",
"minLength": 1
}
}
},
"items": [
{
"name": "Ada"
},
{
"name": ""
},
{
"title": "x"
},
{
"name": "Grace"
}
]
}
}
HTTP (no key)
curl -X POST https://computefirst.net/v1/tools/json-schema-valid-items-filter/versions/1.0.0/execute \
-H "Content-Type: application/json" \
-d '{"schema":{"type":"object","required":["name"],"properties":{"name":{"type":"string","minLength":1}}},"items":[{"name":"Ada"},{"name":""},{"title":"x"},{"name":"Grace"}]}'
The machine-readable contract is at /v1/tools/json-schema-valid-items-filter/versions/1.0.0.
CLI
node cli.mjs run json-schema-valid-items-filter 1.0.0 --input input.json --base-url https://computefirst.net
Get the client at /clients/cli/.
Related tools
- JSON schema batch validate: Validate many JSON records against one Draft 2020-12 subset schema; per-record validity, error pointers, counts.
- JSON schema errors group: Group batch JSON Schema errors by failing schema rule or data path; exact counts and record indexes, stable order.
- JSON array drop keys: Remove specific keys from each object in a JSON array.
- JSON array filter equals: Filter JSON array objects where a key equals a specific value.
- JSON array anti join: Anti join two JSON arrays of objects on exact keys.
- JSON array distinct by: Deduplicate a JSON array of objects based on specific keys.