From b8dc832eea4dd20a6a3e79c9ebb2a1bcc4f8b39a Mon Sep 17 00:00:00 2001 From: Celal Zamanoglu <95054566+celalzamanoglu@users.noreply.github.com> Date: Thu, 18 Dec 2025 19:43:05 +0300 Subject: [PATCH] Jinja interpolation support for natural-language branch criteria (#4325) --- skyvern/forge/sdk/workflow/models/block.py | 36 ++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/skyvern/forge/sdk/workflow/models/block.py b/skyvern/forge/sdk/workflow/models/block.py index 75cda342..a78a4157 100644 --- a/skyvern/forge/sdk/workflow/models/block.py +++ b/skyvern/forge/sdk/workflow/models/block.py @@ -4510,9 +4510,41 @@ class ConditionalBlock(Block): raise ValueError("organization_id is required to evaluate natural language branches") workflow_run_context = evaluation_context.workflow_run_context + template_data = evaluation_context.build_template_data() + + rendered_branch_criteria: list[dict[str, Any]] = [] + for idx, branch in enumerate(branches): + expression = branch.criteria.expression if branch.criteria else "" + rendered_expression = expression + + # Allow Jinja templating inside natural language branch expressions so users can + # mix free text with dynamic values (e.g., "If response: {{ foo.bar }}"). + if "{{" in expression and "}}" in expression: + try: + template = jinja_sandbox_env.from_string(expression) + except Exception as exc: + raise FailedToFormatJinjaStyleParameter( + template=expression, + msg=str(exc), + ) from exc + + if settings.WORKFLOW_TEMPLATING_STRICTNESS == "strict": + if missing := get_missing_variables(expression, template_data): + raise MissingJinjaVariables(template=expression, variables=missing) + + try: + rendered_expression = template.render(template_data) + except Exception as exc: + raise FailedToFormatJinjaStyleParameter( + template=expression, + msg=str(exc), + ) from exc + + rendered_branch_criteria.append({"index": idx, "expression": rendered_expression}) + branch_criteria_payload = [ - {"index": idx, "expression": branch.criteria.expression if branch.criteria else ""} - for idx, branch in enumerate(branches) + {"index": criterion["index"], "expression": criterion["expression"]} + for criterion in rendered_branch_criteria ] extraction_goal = prompt_engine.load_prompt(