Validate Python Block
tt_validate_pythonSecurity-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
| Name | Required | Description | Default |
|---|---|---|---|
| python_code | Yes |