Skip to content

API Reference parrot_tools.browsing.templating

github-actions[bot] edited this page Dec 2, 2026 · 4 revisions

parrot_tools.browsing.templating

View source

Parameter templating and safety bounds for catalogued action steps.

Substitutes {{name}} placeholders in step string fields with caller parameters, and enforces an upper bound on every loop step so a catalogued script can never run unbounded.

Only known parameter names are substituted — unknown placeholders (the Loop executor's {{index}}/{{index_1}}/{{value_name}} among them) pass through untouched, so loop-internal templating keeps working.

Alias ActionParam

Re-exported from parrot_tools.browsing.models.ActionParam.

Alias RESERVED_PLACEHOLDERS

Re-exported from parrot_tools.browsing.models.RESERVED_PLACEHOLDERS.

Function collect_placeholders

Collect every {{name}} placeholder appearing in steps.

Loop-reserved names (index, index_1, value) are excluded globally; a loop's declared value_name is excluded only INSIDE that loop's own subtree — those are runtime placeholders owned by the Loop executor, not action parameters.

collect_placeholders(steps: List[Dict[str, Any]]) -> Set[str]

Parameter Type Default Description
steps List[Dict[str, Any]] Raw DSL step dicts.

Returns: Set[str] — Set of parameter-like placeholder names.

Function collect_value_placeholders

Collect {{name}} placeholders in an arbitrary nested value.

Used to validate composite parameter bindings (ComposedRef.params), where no loop-runtime placeholders exist.

collect_value_placeholders(value: Any) -> Set[str]

Parameter Type Default Description
value Any Any string/dict/list structure.

Returns: Set[str] — Set of placeholder names found.

Function find_literal_credentials

Flag authenticate steps carrying a literal password, recursively.

Catalogued scripts are files at rest — a literal password inside one is a stored secret. Authentication must go through credential_provider (CredentialBroker) instead. Unlike :func:parrot_tools.scraping.models.lint_literal_credentials, this walk also descends into Loop/Conditional nested action lists.

find_literal_credentials(steps: List[Dict[str, Any]]) -> List[str]

Parameter Type Default Description
steps List[Dict[str, Any]] Raw DSL step dicts.

Returns: List[str] — One warning per offending step path (never the credential value).

Function render_steps

Return a deep copy of steps with parameters substituted.

render_steps(steps: List[Dict[str, Any]], params: Dict[str, Any]) -> List[Dict[str, Any]]

Parameter Type Default Description
steps List[Dict[str, Any]] Raw DSL step dicts (never mutated).
params Dict[str, Any] Fully-resolved parameter mapping (see :func:resolve_params).

Returns: List[Dict[str, Any]] — New step dicts ready for execution.

Function render_value

Recursively substitute {{name}} placeholders in value.

A string that is exactly one placeholder is replaced by the raw parameter value (type-preserving, so a list can feed Loop.values); otherwise placeholders are interpolated as strings. Placeholders whose name is not in params are left untouched.

render_value(value: Any, params: Dict[str, Any]) -> Any

Parameter Type Default Description
value Any
params Dict[str, Any]

Returns: Any

Function resolve_params

Merge caller-provided values with declared defaults.

resolve_params(declared: Dict[str, ActionParam], provided: Dict[str, Any] | None) -> Dict[str, Any]

Parameter Type Default Description
declared Dict[str, ActionParam] The action's declared parameters.
provided Dict[str, Any] | None Values supplied by the caller (may be None).

Returns: Dict[str, Any] — Final parameter mapping used for substitution. Extra provided keys are kept (they may feed placeholders of composed children).

Raises:

  • ValueError — A required parameter has neither a value nor a default. All missing names are reported at once.

Function validate_loop_bounds

Enforce an upper bound on every loop step, recursively.

Loops are allowed but only bounded: each loop must resolve to at most max_iterations iterations. In strict mode (save time) a violation raises; in non-strict mode (run time, defense in depth) offending values are clamped.

validate_loop_bounds(steps: List[Dict[str, Any]], max_iterations: int, *, strict: bool = True) -> List[Dict[str, Any]]

Parameter Type Default Description
steps List[Dict[str, Any]] Raw DSL step dicts (never mutated).
max_iterations int Hard per-loop iteration cap.
strict bool True Raise instead of clamping.

Returns: List[Dict[str, Any]] — A deep copy of steps with loop bounds enforced.

Raises:

  • ValueError — In strict mode, when a loop exceeds or lacks a bound.

Architecture

Clients

Bots & Agents

Memory

Knowledge

Tools & Toolkits

Flows

Experts

Skills

Stores & Loaders

MCP & A2A

Server & APIs

Integrations

Outputs & A2UI

Prompts

Security

Operations

Migration

SDD Tooling

LLM Wiki

Deployment

Decisions

API Reference

Clone this wiki locally