The intent_guard.py module#

Summary#

GuardFinding

Single signature hit on a snippet.

GuardReport

Collection of findings for a snippet.

is_enabled

Honor FLUIDS_MCP_INTENT_GUARD (default ON).

evaluate

Evaluate code against intent-guard risk signatures.

Description#

Static, Fluent-specific risk classifier for run_code snippets.

This module is stateless. It does NOT plan, schedule, or track history. It only inspects a single snippet’s AST against a fixed table of Fluent-specific crash signatures and (optionally) performs a single intra-snippet topological reorder when use-before-create is detected for a small set of well-known dependencies (such as named expressions and materials).

By design this module:

  • Contains no model orchestration and no rule-pack DSL. Only a fixed table of code shapes that have empirically crashed PyFluent/the gRPC channel during in-house sessions.

  • Is opt-out via FLUIDS_MCP_INTENT_GUARD=0 so a host that prefers its own planner can disable it entirely.

  • Never imports ansys.fluent.core. It pure ast walks only so that it is safe to evaluate before a solver session exists.

  • Returns the same RunCodeResult envelope the rest of the leaf uses, with one of three new error_code values: risk_blocked, sequence_error, and solver_disconnected. (The third is set by pyfluent backend, not here.)

This is a defense-in-depth layer at the execution boundary, in scope for the standalone leaf. It is NOT a planner. Higher-level planning, recipes, and journaling remain out of scope.

Module detail#

intent_guard.is_enabled(env: dict[str, str] | None = None) bool#

Honor FLUIDS_MCP_INTENT_GUARD (default ON).

Parameters:
envdict[str, str], optional

Environment mapping to inspect. When omitted, os.environ is used.

Returns:
bool

False only when the environment value is 0, false, no, or off. Otherwise, True.

intent_guard.evaluate(code: str, *, live_named_objects: Mapping[str, Iterable[str]] | None = None, iterating: bool = False) GuardReport#

Evaluate code against intent-guard risk signatures.

Parameters:
codestr

Python code or command text to execute or validate.

live_named_objectsOptional[Mapping[str, Iterable[str]]]

Live named objects to supply to the function.

iteratingbool

Whether to enable or apply iterating.

Returns:
GuardReport

GuardReport produced by the operation.