Skip to content

Fix JSON schema flow state kickoff inputs#6325

Merged
vinibrsl merged 1 commit into
mainfrom
fix-flow-definition-defaults
Jun 24, 2026
Merged

Fix JSON schema flow state kickoff inputs#6325
vinibrsl merged 1 commit into
mainfrom
fix-flow-definition-defaults

Conversation

@vinibrsl

@vinibrsl vinibrsl commented Jun 24, 2026

Copy link
Copy Markdown
Member

Allow required JSON schema state fields to be supplied by kickoff inputs instead of requiring every field to exist in state.default before runtime.

Example: a flow with required lead_name and no state.default can now run with kickoff inputs={"lead_name": "Ada Lovelace"}.


Note

Low Risk
Small, targeted change to initial state construction; non-missing validation still fails fast, and kickoff continues to validate merged state.

Overview
JSON-schema flows no longer fail at startup when required fields are absent from state.default. _build_definition_state_model still tries normal construction from defaults; if Pydantic reports only missing field errors, it falls back to model_construct so kickoff can supply those values via _initialize_state. Any other validation errors are unchanged and still raise.

A regression test covers a declarative flow with a required lead_name and no default, kicked off with inputs={"lead_name": "Ada Lovelace"}.

Reviewed by Cursor Bugbot for commit d3c2fff. Bugbot is set up for automated code reviews on this repo. Configure here.

Summary by CodeRabbit

  • Bug Fixes
    • Improved handling of required input fields when starting a flow, so missing-field validation no longer blocks runs that provide those values at launch.
    • Flows using structured state now preserve supplied input data more reliably, including required fields and generated identifiers.
  • Tests
    • Added coverage for flows with required structured state fields provided through kickoff inputs.

Allow required JSON schema state fields to be supplied by kickoff inputs
instead of requiring every field to exist in state.default before
runtime.

Example: a flow with required lead_name and no state.default can now run
with kickoff inputs={"lead_name": "Ada Lovelace"}.

@corridor-security corridor-security Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Summary: This PR changes JSON schema flow state construction to permit missing required state fields at initialization when they are expected to be provided later via kickoff inputs; no exploitable security vulnerabilities were identified.

Risk: Low risk. The change affects internal state validation behavior and does not introduce a new public endpoint, authentication/authorization boundary, external integration, or direct handling of sensitive data.

@coderabbitai

coderabbitai Bot commented Jun 24, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 83f952bd-17eb-4547-b2a0-61b1f435b223

📥 Commits

Reviewing files that changed from the base of the PR and between 5827abb and d3c2fff.

📒 Files selected for processing (2)
  • lib/crewai/src/crewai/flow/runtime/__init__.py
  • lib/crewai/tests/test_flow_from_definition.py

📝 Walkthrough

Walkthrough

Flow state construction now falls back to unvalidated model construction when validation fails only because required fields are missing. Tests add a json_schema flow fixture and verify required state values can be supplied through kickoff(inputs=...).

Changes

JSON schema state fallback

Layer / File(s) Summary
State construction fallback
lib/crewai/src/crewai/flow/runtime/__init__.py
_build_definition_state_model catches missing-field ValidationErrors and uses model_construct(**kwargs) in that case; other validation errors are re-raised.
Required-input fixture and kickoff test
lib/crewai/tests/test_flow_from_definition.py
A new fixture defines a required lead_name field in json_schema state, and a test checks kickoff(inputs=...) populates the field, returns it from begin, and includes an id in the resulting state.

Suggested reviewers

  • joaomdmoura
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: allowing required JSON schema flow state fields to be provided via kickoff inputs.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix-flow-definition-defaults

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@vinibrsl vinibrsl merged commit 156b350 into main Jun 24, 2026
58 checks passed
@vinibrsl vinibrsl deleted the fix-flow-definition-defaults branch June 24, 2026 20:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants