Skip to main content
Glama

Validate Python Block

tt_validate_python
Read-onlyIdempotent

Security-check a custom Python snippet before embedding it in a strategy.

Custom Python in a Tradetron strategy runs on shared TT infrastructure, so it is gated by a strict deterministic policy: Tradetron keywords and the tt_-prefixed transient wrappers tt_set_runtime/tt_get_runtime are allowed (the BARE get_runtime/set_runtime are the raw engine functions and must never be called from a block — they raise at live deploy, and are flagged here as a warning); imports, dunder/ introspection access, eval/exec/compile/open/getattr/globals, string .format() escapes, function definitions (def and lambda), and huge allocations are rejected. Loops only when bounded: a for over range() with integer-literal bounds or a literal tuple/list, at most 100 iterations per loop, 500 per block, 2 levels deep — while and comprehensions are rejected. Use a loop only where the logic cannot be written without one.

Call this BEFORE proposing python_code in tt_create_strategy / tt_update_strategy. Returns {valid, code_hash, errors[], warnings[]} with a specific code + message + line for each issue, so you can fix the snippet without a round-trip. The same gate runs server-side on every create/edit, so anything this rejects will also be rejected on save.

code_hash is the sha256 of the NORMALISED code — line endings unified, per-line trailing whitespace removed, leading and trailing blank lines dropped — which is also the form the code is saved in. So the hash of what you sent matches the hash of what reads back, and a trailing newline you add is not stored.

Tool call template

Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.

{
  "id": 1,
  "jsonrpc": "2.0",
  "method": "tools/call",
  "params": {
    "arguments": {
      "python_code": "<python_code>"
    },
    "name": "tt_validate_python"
  }
}

Input Schema

NameRequiredDescriptionDefault
python_codeYes

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observed

TDQS

A4.8/5.0
Behavior5/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

Annotations only cover the safety profile (readOnly/idempotent/non-destructive); the description goes far beyond by enumerating the exact deterministic policy — allowed keywords, the tt_set_runtime/tt_get_runtime vs bare get_runtime distinction with the warning behavior, rejected constructs, and loop bounds. It also explains code_hash normalisation (line endings, trailing whitespace, blank lines) and the errors/warnings distinction, so no behaviour is left to discovery.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Front-loaded with purpose and the call-before instruction, then structured as policy rules, usage note, and return contract. It is long (~250 words) but nearly every clause carries operational meaning; only the parenthetical dunder/introspection list is slightly sprawling.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness5/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

There is no output schema, yet the description fully specifies the return shape {valid, code_hash, errors[], warnings[]} including per-issue code/message/line, and the normalisation semantics of code_hash. For a one-parameter validator, nothing an agent needs to call it and act on the result is missing.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The single parameter has 0% schema coverage, but the description compensates by defining the policy the python_code string is validated against and by specifying that the hash is computed over the normalised form rather than the raw input. It never states the parameter name or that it must be non-empty raw source, which keeps it just short of a 5.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

States a specific verb+resource ("Security-check a custom Python snippet") and scoped object (before embedding in a Tradetron strategy), which clearly separates it from sibling tools like tt_validate_markdown and the create/update tools.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines5/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

Explicitly says when to call it ("BEFORE proposing python_code in tt_create_strategy / tt_update_strategy") and why it is sufficient ("the same gate runs server-side on every create/edit, so anything this rejects will also be rejected on save"). It also gives a design guideline ("Use a loop only where the logic cannot be written without one"), leaving no ambiguity about placement in the workflow.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Try in Browser

Glama MCP Gateway

Add one secure layer between your agents and this server.

Resources