Skip to content

fix: coerce schedule fields to str to prevent ValidationError with integer inputs#1537

Open
octo-patch wants to merge 1 commit into
agent0ai:mainfrom
octo-patch:fix/issue-1473-taskschedule-int-coercion
Open

fix: coerce schedule fields to str to prevent ValidationError with integer inputs#1537
octo-patch wants to merge 1 commit into
agent0ai:mainfrom
octo-patch:fix/issue-1473-taskschedule-int-coercion

Conversation

@octo-patch
Copy link
Copy Markdown
Contributor

Fixes #1473

Problem

When an LLM outputs numeric values (e.g. 0, 9) for cron schedule fields instead of strings, create_scheduled_task crashes with a pydantic_core.ValidationError:

ValidationError: 2 validation errors for TaskSchedule
minute
  Input should be a valid string [type=string_type, input_value=0, input_type=int]
hour
  Input should be a valid string [type=string_type, input_value=9, input_type=int]

Pydantic v2 does not auto-coerce intstr, and LLMs frequently output integers for numeric cron fields (e.g. 0 instead of "0").

Solution

Wrap all schedule field values with str() at both construction sites:

  • tools/scheduler.pycreate_scheduled_task(): coerce each cron field before passing to TaskSchedule
  • helpers/task_scheduler.pyparse_task_schedule(): same coercion when parsing a schedule dict

This is a non-breaking, minimal fix. str(int) and str(str) both produce the correct string value, so there is no behavior change for already-valid inputs.

Testing

The fix can be verified manually:

from helpers.task_scheduler import TaskSchedule
# Previously raised ValidationError; now works correctly
schedule = TaskSchedule(minute=str(0), hour=str(9), day=str("*"), month=str("*"), weekday=str("*"))
print(schedule.to_crontab())  # "0 9 * * *"

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.

TaskSchedule ValidationError when LLM passes integers for cron schedule fields

1 participant