Skip to content

fix: handle enum types correctly in json_schema_to_model#301

Open
octo-patch wants to merge 1 commit intoPySpur-Dev:mainfrom
octo-patch:fix/issue-291-enum-validation-in-json-schema-to-model
Open

fix: handle enum types correctly in json_schema_to_model#301
octo-patch wants to merge 1 commit intoPySpur-Dev:mainfrom
octo-patch:fix/issue-291-enum-validation-in-json-schema-to-model

Conversation

@octo-patch
Copy link
Copy Markdown

Fixes #291

Problem

SendEmailNode (and other nodes with has_fixed_output=True and enum fields) throws a Pydantic validation error at runtime:

ValidationError: 1 validation error for SendEmailNode_1
provider
  Input should be a valid dictionary or instance of EmailProvider
  [type=model_type, input_value=<EmailProvider.RESEND: 'resend'>, input_type=EmailProvider]

Root cause: When setup() processes output_json_schema for a node with has_fixed_output=True, it calls json_schema_to_model(). That function recursively calls itself on every $defs entry — including enum definitions like EmailProvider. Because enum schemas have no properties, json_schema_to_model creates an empty Pydantic model for them. Later, when json_schema_to_pydantic_type resolves the $ref, the field type becomes that empty model instead of str. Pydantic then rejects the actual enum value with "Input should be a valid dictionary or instance of EmailProvider".

Solution

In json_schema_to_model, before recursively converting a $defs entry, check whether the definition contains an "enum" field. If it does, map it to the appropriate Python primitive type (str, int, float, bool) instead of creating a Pydantic model. This correctly handles all JSON Schema enum types that reference a primitive base type.

Testing

Manually traced the code path for SendEmailNodeOutput.model_json_schema():

  • EmailProvider definition ({"enum": ["resend", "sendgrid"], "type": "string"}) now maps to str in defs
  • provider field resolves to str, accepting both enum instances and raw string values
  • Existing model/object definitions continue to be processed via json_schema_to_model as before

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.

Error in SendMailNode

1 participant