Skip to content

Validate response schema#166

Merged
rgambee merged 4 commits intomainfrom
validate-response-schema
Feb 19, 2026
Merged

Validate response schema#166
rgambee merged 4 commits intomainfrom
validate-response-schema

Conversation

@rgambee
Copy link
Contributor

@rgambee rgambee commented Feb 19, 2026

This validates that the response schema passed to the MCP tools is valid JSON schema. It needs to look like

"response_schema": {
  "type": "object",
  "properties": {
    "population": {"type": "string"},
    "year": {"type": "string"}
  }
}

This is not allowed

"response_schema": {
  "population": "string",
  "year": "string"
}

To be clear, the second format has never been allowed. But now the MCP server will yell at you if you try to use it. Previously it would have silently turned your schema into the empty one, which meant you'd get no results.

I also updated the documentation a bit to try to clarify this.

@rgambee rgambee requested a review from nikosbosse February 19, 2026 20:14
@rgambee rgambee merged commit 88dc36f into main Feb 19, 2026
6 checks passed
@rgambee rgambee deleted the validate-response-schema branch February 19, 2026 20:18
Comment on lines 996 to 1006
required = set(schema.get("required", []))

fields: dict[str, Any] = {}
for field_name, field_def in properties.items():
if field_name.startswith("_") or not isinstance(field_def, dict):
continue
if not isinstance(field_def, dict):
raise ValueError(
f"Invalid property schema for '{field_name}': expected an object."
)

field_type_str = field_def.get("type", "string")
python_type = JSON_TYPE_MAP.get(field_type_str, str)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: The new _validate_response_schema function allows underscore-prefixed field names, but Pydantic's create_model later silently ignores them, leading to unexpected data loss.
Severity: MEDIUM

Suggested Fix

Update the _validate_response_schema function to iterate through the properties in the schema and explicitly raise a ValueError if any field name starts with an underscore, similar to how other schema validations are performed.

Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent.
Verify if this is a real issue. If it is, propose a fix; if not, explain why it's not
valid.

Location: everyrow-mcp/src/everyrow_mcp/server.py#L992-L1006

Potential issue: The new validation function `_validate_response_schema` does not
prohibit field names that start with an underscore. While the old code explicitly
skipped these fields, the new logic allows them to pass validation. However, the
downstream call to Pydantic's `create_model` in `_schema_to_model` will silently ignore
any fields prefixed with an underscore, only issuing a `RuntimeWarning`. This
discrepancy means a schema with a field like `_internal_id` will be considered valid,
but the corresponding data will not be captured, resulting in silent data loss.

Did we get this right? 👍 / 👎 to inform future reviews.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant