fix(crew): only report real template variables in fetch_inputs#5900
fix(crew): only report real template variables in fetch_inputs#5900ATOM00blue wants to merge 1 commit into
Conversation
fetch_inputs used a loose `{(.+?)}` regex that matched any braces,
including literal JSON examples and output schemas embedded in task
descriptions or agent backstories. Those are never substituted by
interpolate_only, so they were reported as required inputs that could
not be filled. Reuse the canonical template-variable pattern shared with
interpolate_only so discovery and substitution stay in sync.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (3)
📝 WalkthroughWalkthroughThis PR refactors template variable pattern extraction into a shared constant exported from ChangesTemplate Pattern Extraction Consolidation
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Pull request overview
Aligns Crew.fetch_inputs() with the actual interpolation semantics used by interpolate_only(), so input discovery reports only real template variables (and ignores literal braces common in JSON/schema examples).
Changes:
- Introduced a shared
TEMPLATE_VARIABLE_PATTERNregex instring_utils(used byinterpolate_only). - Updated
Crew.fetch_inputs()to useTEMPLATE_VARIABLE_PATTERNinstead of a broad{...}matcher. - Added a regression test ensuring literal braces / non-identifier placeholders are not reported as required inputs.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| lib/crewai/tests/test_crew.py | Adds a regression test covering literal braces and non-identifier brace content in prompts. |
| lib/crewai/src/crewai/utilities/string_utils.py | Promotes the interpolation regex to TEMPLATE_VARIABLE_PATTERN and reuses it in interpolate_only. |
| lib/crewai/src/crewai/crew.py | Makes fetch_inputs() reuse the canonical template-variable pattern and removes the unused re import. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| @@ -9,7 +9,9 @@ | |||
| import unicodedata | |||
|
|
|||
|
|
|||
Problem
Crew.fetch_inputs()is meant to return the placeholder names a crew expects so callers know what to pass tokickoff(). It scans task descriptions / expected outputs and agent role/goal/backstory with the regex\{(.+?)}, which matches any content between braces.That regex does not match what actually gets interpolated.
interpolate_only()(the function that performs the substitution) only replaces valid identifiers via\{([A-Za-z_][A-Za-z0-9_\-]*)}. As a result, literal braces that are common in prompts — embedded JSON examples, output schemas, etc. — are reported as required inputs even though they are never substituted.Example:
The bogus entries are not real variables, so any value passed for them via
kickoff(inputs=...)is silently ignored, and tools that build UIs/prompts fromfetch_inputs()surface placeholders that can never be filled.Fix
Reuse the canonical template-variable pattern that
interpolate_onlyalready uses, so input discovery and input substitution share a single source of truth and cannot drift. The pattern is promoted to a publicTEMPLATE_VARIABLE_PATTERNinstring_utilsand imported bycrew.py. The now-unusedreimport increw.pyis removed.Testing
test_fetch_inputs_ignores_literal_braces, which fails onmain(returns the JSON fragments as inputs) and passes with this change.test_fetch_inputsand the task/crew interpolation tests still pass.ruff check,ruff format --check, andmypyare clean on the changed files.Developed with AI coding assistance; reviewed and submitted by the author.
Per CONTRIBUTING.md, this PR should carry the
llm-generatedlabel — I do not have permission to apply labels as an external contributor, so could a maintainer please add it.Summary by CodeRabbit