validateWorkflowSource function
Validates Python workflow source against the run_workflow rules, so a
disallowed script fails before the model is asked to run it.
Rejects, with a WorkflowException:
importandfrom ... importstatements;whileloops (use boundedforloops);- attributes starting with
_and names starting with__; returnoutside a nesteddef, andyieldanywhere;- unterminated strings, unbalanced brackets, and inconsistent indentation,
reported as
workflow syntax error.
This is a lexical check, not a full Python parser: a script that passes may still contain syntax errors, which the harness reports when it runs the script. Expressions inside f-strings are not inspected.
Implementation
void validateWorkflowSource(String source) {
final lines = _PythonLexer(source).logicalLines();
_checkIndentation(lines);
_checkReturnAndYield(lines);
for (final line in lines) {
_checkLine(line);
}
}