Python Code Validator
Proves AI-generated Python does what you asked: lint, types, security, sandbox run, exact fixes.
我该使用它吗
质量与安全性
基于对工具定义和协议合规性的自动分析。
上下文开销
这是每次将服务器的工具加载到模型上下文窗口时所消耗的大致 token 数。数值越高,可用于其他任务的注意力就越少。
安装
一键安装
将以下内容添加到你的 `claude_desktop_config.json` 文件中:
{
"mcpServers": {
"python-code-validator": {
"url": "https://api.statemind.ai/mcp"
}
}
}远程端点
https://api.statemind.ai/mcpstreamable-http它能做什么
工具清单
工具(3)
🟢validate_python(code, language, options)
Check Python source without running it: parse, lint (ruff), type-check (mypy), AST security policy, credential scan. Safe on code you do not trust. Use it on every Python file you generated or edited, before writing it to disk. Alternatives: repair_python to get the corrected source instead of the diagnosis; execute_python to prove the code runs. Auth: a key is required. A free key covers this call, 25 per day, then HTTP 429; get one with POST /v1/keys. Credits are bought without an account, 1 per call: GET /v1/pricing says where to send the xDAI. Or pay for this one call with no key at all: call it without one and the result carries x402 payment requirements ($0.01 in USD Coin on eip155:8453); sign them and repeat the call with the payment in _meta['x402/payment']. Arguments: code: the whole file, 1..200000 bytes of UTF-8 measured after encoding (empty is refused with 400, larger with 413); a fragment is fine, but line and column numbers in the answer count from 1 in what you sent. language: must be 'python'; anything else is 400, and the field may be omitted. Of options only transpile_to (e.g. 'javascript', which returns a translated copy in transpiled) acts here; timeout_s, max_iterations, optimize, examples and expected_output need a pass that rewrites or runs the code, so send code alone. Ignored options are not refused, so a call that sets them looks like it worked; and code that does not parse is answered rather than refused: valid=false with the syntax error located, which is the point. Returns valid, score 0..1, diagnostics (rule, message, line, column), security findings, fixes, fixed_code and runtime; see outputSchema. The code and its verdict are retained to improve the service.
输入模式
{
"type": "object",
"properties": {
"code": {
"description": "The source to check, as a whole file where possible: diagnostics carry the line and column of the text you send, and a fragment hides the imports and definitions the type check needs. A deployment may accept fewer bytes than the 200000 here.",
"maxLength": 200000,
"minLength": 1,
"title": "Code",
"type": "string"
},
"language": {
"$ref": "#/$defs/Language",
"default": "python",
"description": "The language of the code. A service that does not handle it refuses the request rather than guessing; the enum is shared across services, so it lists more than any one of them accepts."
},
"options": {
"$ref": "#/$defs/Options",
"description": "Tuning knobs. Most of them only take effect in the mode that does the corresponding work; see each field."
}
},
"required": [
"code"
],
"$defs": {
"Language": {
"description": "Source languages a validator can accept.",
"enum": [
"python",
"javascript",
"typescript",
"html",
"sql",
"solidity",
"other"
],
"title": "Language",
"type": "string"
},
"Mode": {
"description": "How much work the service is allowed to do.\n\n``static``\n Never executes the submitted code. Parsing, linting and security\n scanning only. This is the default and the only mode that is safe to\n expose without a container sandbox.\n``repair``\n Static mode plus deterministic auto-fixes and refactors.\n``execute``\n Repair plus running the code inside a sandbox to prove it works.",
"enum": [
"static",
"repair",
"execute"
],
"title": "Mode",
"type": "string"
},
"Options": {
"description": "Per-request tuning knobs.",
"properties": {
"timeout_s": {
"anyOf": [
{
"exclusiveMinimum": 0,
"maximum": 60,
"type": "number"
},
{
"type": "null"
}
],
"default": null,
"description": "Wall-clock budget for running the code. Omitted means the service's own default (MSVC_DEFAULT_TIMEOUT_S). Only execute mode runs anything; a deployment may cap this below the 60 the schema allows and refuses a larger value.",
"title": "Timeout S"
},
"max_iterations": {
"default": 3,
"description": "How many fix/verify rounds the repair loop may take. Ignored in static mode, which changes nothing.",
"maximum": 10,
"minimum": 1,
"title": "Max Iterations",
"type": "integer"
},
"transpile_to": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
],
"default": null,
"description": "Target language for a transpiled copy, e.g. 'javascript'. The copy is made from the code as it ends up, so in repair and execute mode it translates the repaired source rather than the submitted one.",
"title": "Transpile To"
},
"expected_output": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
],
"default": null,
"description": "Exact stdout the code must produce in execute mode. A mismatch is an 'expected-output' diagnostic and makes the response invalid, even when the program exits cleanly. Ignored in the other modes, which produce no output.",
"title": "Expected Output"
},
"examples": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
],
"default": null,
"description": "What the code is supposed to do, as doctest lines ('>>> f(2)' on one line, '4' on the next) or as plain assertions ('assert f(2) == 4'). In execute mode they are run in the sandbox: an example that does not hold is a 'python:example-mismatch' error and makes the response invalid, and repair searches for a single-token change that makes every one of them pass. This is the only way the service can tell code that runs from code that is right, so send it whenever you know what you asked for. Examples already written in the code ('>>> ' in any string) are used the same way without this option. Ignored in the other modes, which run nothing.",
"title": "Examples"
},
"optimize": {
"default": false,
"description": "Run constant folding / dead-code elimination. Off by default: the optimiser rewrites the program, and a rewrite is only returned when it provably keeps every effectful construct.",
"title": "Optimize",
"type": "boolean"
}
},
"title": "Options",
"type": "object"
}
},
"description": "A validation job submitted by an agent.",
"title": "ValidateRequest"
}输出模式
{
"type": "object",
"properties": {
"valid": {
"title": "Valid",
"type": "boolean"
},
"score": {
"maximum": 1,
"minimum": 0,
"title": "Score",
"type": "number"
},
"diagnostics": {
"items": {
"$ref": "#/$defs/Diagnostic"
},
"title": "Diagnostics",
"type": "array"
},
"security": {
"items": {
"$ref": "#/$defs/SecurityFinding"
},
"title": "Security",
"type": "array"
},
"fixes": {
"items": {
"type": "string"
},
"title": "Fixes",
"type": "array"
},
"fixed_code": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
],
"default": null,
"title": "Fixed Code"
},
"transpiled": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
],
"default": null,
"title": "Transpiled"
},
"runtime": {
"$ref": "#/$defs/RuntimeReport"
},
"meta": {
"$ref": "#/$defs/Meta"
}
},
"required": [
"valid",
"score",
"meta"
],
"$defs": {
"AIReport": {
"description": "What the optional AI refinement backend contributed.\n\nAbsent from a response when no backend is configured. Present but with\n``consulted=False`` when the deterministic fixers settled the code on their\nown, so a caller can tell \"the model was never needed\" apart from \"the\nmodel was asked and came back empty-handed\".",
"properties": {
"consulted": {
"default": false,
"title": "Consulted",
"type": "boolean"
},
"backend": {
"default": "",
"title": "Backend",
"type": "string"
},
"calls": {
"default": 0,
"title": "Calls",
"type": "integer"
},
"duration_ms": {
"default": 0,
"title": "Duration Ms",
"type": "integer"
},
"outcome": {
"default": "not-consulted",
"title": "Outcome",
"type": "string"
},
"detail": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
],
"default": null,
"title": "Detail"
}
},
"title": "AIReport",
"type": "object"
},
"Diagnostic": {
"description": "A correctness problem found in the code.",
"properties": {
"severity": {
"$ref": "#/$defs/Severity"
},
"rule": {
"title": "Rule",
"type": "string"
},
"message": {
"title": "Message",
"type": "string"
},
"line": {
"anyOf": [
{
"type": "integer"
},
{
"type": "null"
}
],
"default": null,
"title": "Line"
},
"column": {
"anyOf": [
{
"type": "integer"
},
{
"type": "null"
}
],
"default": null,
"title": "Column"
}
},
"required": [
"severity",
"rule",
"message"
],
"title": "Diagnostic",
"type": "object"
},
"Meta": {
"description": "Provenance of a response, so results stay reproducible.",
"properties": {
"service": {
"title": "Service",
"type": "string"
},
"version": {
"title": "Version",
"type": "string"
},
"api": {
"default": "v1",
"title": "Api",
"type": "string"
},
"engine": {
"additionalProperties": {
"type": "string"
},
"title": "Engine",
"type": "object"
},
"ai": {
"anyOf": [
{
"$ref": "#/$defs/AIReport"
},
{
"type": "null"
}
],
"default": null
},
"mode": {
"$ref": "#/$defs/Mode",
"default": "static"
},
"duration_ms": {
"default": 0,
"title": "Duration Ms",
"type": "integer"
},
"request_id": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
],
"default": null,
"title": "Request Id"
}
},
"required": [
"service",
"version"
],
"title": "Meta",
"type": "object"
},
"Mode": {
"description": "How much work the service is allowed to do.\n\n``static``\n Never executes the submitted code. Parsing, linting and security\n scanning only. This is the default and the only mode that is safe to\n expose without a container sandbox.\n``repair``\n Static mode plus deterministic auto-fixes and refactors.\n``execute``\n Repair plus running the code inside a sandbox to prove it works.",
"enum": [
"static",
"repair",
"execute"
],
"title": "Mode",
"type": "string"
},
"RuntimeReport": {
"description": "Outcome of executing the code in a sandbox.",
"properties": {
"ran": {
"default": false,
"title": "Ran",
"type": "boolean"
},
"returncode": {
"anyOf": [
{
"type": "integer"
},
{
"type": "null"
}
],
"default": null,
"title": "Returncode"
},
"stdout": {
"default": "",
"title": "Stdout",
"type": "string"
},
"stderr": {
"default": "",
"title": "Stderr",
"type": "string"
},
"duration_ms": {
"anyOf": [
{
"type": "integer"
},
{
"type": "null"
}
],
"default": null,
"title": "Duration Ms"
},
"timed_out": {
"default": false,
"title": "Timed Out",
"type": "boolean"
},
"sandbox": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
],
"default": null,
"title": "Sandbox"
}
},
"title": "RuntimeReport",
"type": "object"
},
"SecurityFinding": {
"description": "A security problem reported by one of the scanners.",
"properties": {
"tool": {
"title": "Tool",
"type": "string"
},
"id": {
"title": "Id",
"type": "string"
},
"severity": {
"$ref": "#/$defs/Severity"
},
"confidence": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
],
"default": null,
"title": "Confidence"
},
"message": {
"title": "Message",
"type": "string"
},
"line": {
"anyOf": [
{
"type": "integer"
},
{
"type": "null"
}
],
"default": null,
"title": "Line"
},
"cwe": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
],
"default": null,
"title": "Cwe"
}
},
"required": [
"tool",
"id",
"severity",
"message"
],
"title": "SecurityFinding",
"type": "object"
},
"Severity": {
"description": "Severity of a single finding.",
"enum": [
"error",
"warning",
"info"
],
"title": "Severity",
"type": "string"
}
},
"description": "The result an agent gets back and pays for.",
"title": "ValidateResponse"
}🟢repair_python(code, language, options)
Everything validation does, plus deterministic fixes: the corrected source comes back in fixed_code, and the original is kept whenever the fix cannot be proven safe. The code is still never run. Use it when validation failed and you want the fix rather than the diagnosis. Alternatives: validate_python when the diagnosis is enough; execute_python when the fix has to be proven to run. Auth: a key is required. This call needs a paid key and answers HTTP 402 without one. Credits are bought without an account, 3 per call: GET /v1/pricing says where to send the xDAI. Or pay for this one call with no key at all: call it without one and the result carries x402 payment requirements ($0.03 in USD Coin on eip155:8453); sign them and repeat the call with the payment in _meta['x402/payment']. Arguments: code: the whole file, 1..200000 bytes of UTF-8 measured after encoding (empty is refused with 400, larger with 413); a fragment is fine, but line and column numbers in the answer count from 1 in what you sent. language: must be 'python'; anything else is 400, and the field may be omitted. options.max_iterations (1..10, default 3) caps the fix/verify rounds: raise it for a file with several independent faults, leave it for a snippet. options.optimize (default false) additionally folds constants and drops dead code, and is only worth setting when you asked for a rewrite anyway. options.transpile_to (e.g. 'javascript') returns a translation of the *repaired* source in transpiled, not of what you sent. fixed_code is null when nothing could be proven safe to change, so treat null as 'no fix', not as an error. options.timeout_s, options.examples and options.expected_output do nothing here: nothing is run, so there is no clock, no stdout, and no way to check an example. Returns valid, score 0..1, diagnostics (rule, message, line, column), security findings, fixes, fixed_code and runtime; see outputSchema. The code and its verdict are retained to improve the service.
输入模式
{
"type": "object",
"properties": {
"code": {
"description": "The source to check, as a whole file where possible: diagnostics carry the line and column of the text you send, and a fragment hides the imports and definitions the type check needs. A deployment may accept fewer bytes than the 200000 here.",
"maxLength": 200000,
"minLength": 1,
"title": "Code",
"type": "string"
},
"language": {
"$ref": "#/$defs/Language",
"default": "python",
"description": "The language of the code. A service that does not handle it refuses the request rather than guessing; the enum is shared across services, so it lists more than any one of them accepts."
},
"options": {
"$ref": "#/$defs/Options",
"description": "Tuning knobs. Most of them only take effect in the mode that does the corresponding work; see each field."
}
},
"required": [
"code"
],
"$defs": {
"Language": {
"description": "Source languages a validator can accept.",
"enum": [
"python",
"javascript",
"typescript",
"html",
"sql",
"solidity",
"other"
],
"title": "Language",
"type": "string"
},
"Mode": {
"description": "How much work the service is allowed to do.\n\n``static``\n Never executes the submitted code. Parsing, linting and security\n scanning only. This is the default and the only mode that is safe to\n expose without a container sandbox.\n``repair``\n Static mode plus deterministic auto-fixes and refactors.\n``execute``\n Repair plus running the code inside a sandbox to prove it works.",
"enum": [
"static",
"repair",
"execute"
],
"title": "Mode",
"type": "string"
},
"Options": {
"description": "Per-request tuning knobs.",
"properties": {
"timeout_s": {
"anyOf": [
{
"exclusiveMinimum": 0,
"maximum": 60,
"type": "number"
},
{
"type": "null"
}
],
"default": null,
"description": "Wall-clock budget for running the code. Omitted means the service's own default (MSVC_DEFAULT_TIMEOUT_S). Only execute mode runs anything; a deployment may cap this below the 60 the schema allows and refuses a larger value.",
"title": "Timeout S"
},
"max_iterations": {
"default": 3,
"description": "How many fix/verify rounds the repair loop may take. Ignored in static mode, which changes nothing.",
"maximum": 10,
"minimum": 1,
"title": "Max Iterations",
"type": "integer"
},
"transpile_to": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
],
"default": null,
"description": "Target language for a transpiled copy, e.g. 'javascript'. The copy is made from the code as it ends up, so in repair and execute mode it translates the repaired source rather than the submitted one.",
"title": "Transpile To"
},
"expected_output": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
],
"default": null,
"description": "Exact stdout the code must produce in execute mode. A mismatch is an 'expected-output' diagnostic and makes the response invalid, even when the program exits cleanly. Ignored in the other modes, which produce no output.",
"title": "Expected Output"
},
"examples": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
],
"default": null,
"description": "What the code is supposed to do, as doctest lines ('>>> f(2)' on one line, '4' on the next) or as plain assertions ('assert f(2) == 4'). In execute mode they are run in the sandbox: an example that does not hold is a 'python:example-mismatch' error and makes the response invalid, and repair searches for a single-token change that makes every one of them pass. This is the only way the service can tell code that runs from code that is right, so send it whenever you know what you asked for. Examples already written in the code ('>>> ' in any string) are used the same way without this option. Ignored in the other modes, which run nothing.",
"title": "Examples"
},
"optimize": {
"default": false,
"description": "Run constant folding / dead-code elimination. Off by default: the optimiser rewrites the program, and a rewrite is only returned when it provably keeps every effectful construct.",
"title": "Optimize",
"type": "boolean"
}
},
"title": "Options",
"type": "object"
}
},
"description": "A validation job submitted by an agent.",
"title": "ValidateRequest"
}输出模式
{
"type": "object",
"properties": {
"valid": {
"title": "Valid",
"type": "boolean"
},
"score": {
"maximum": 1,
"minimum": 0,
"title": "Score",
"type": "number"
},
"diagnostics": {
"items": {
"$ref": "#/$defs/Diagnostic"
},
"title": "Diagnostics",
"type": "array"
},
"security": {
"items": {
"$ref": "#/$defs/SecurityFinding"
},
"title": "Security",
"type": "array"
},
"fixes": {
"items": {
"type": "string"
},
"title": "Fixes",
"type": "array"
},
"fixed_code": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
],
"default": null,
"title": "Fixed Code"
},
"transpiled": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
],
"default": null,
"title": "Transpiled"
},
"runtime": {
"$ref": "#/$defs/RuntimeReport"
},
"meta": {
"$ref": "#/$defs/Meta"
}
},
"required": [
"valid",
"score",
"meta"
],
"$defs": {
"AIReport": {
"description": "What the optional AI refinement backend contributed.\n\nAbsent from a response when no backend is configured. Present but with\n``consulted=False`` when the deterministic fixers settled the code on their\nown, so a caller can tell \"the model was never needed\" apart from \"the\nmodel was asked and came back empty-handed\".",
"properties": {
"consulted": {
"default": false,
"title": "Consulted",
"type": "boolean"
},
"backend": {
"default": "",
"title": "Backend",
"type": "string"
},
"calls": {
"default": 0,
"title": "Calls",
"type": "integer"
},
"duration_ms": {
"default": 0,
"title": "Duration Ms",
"type": "integer"
},
"outcome": {
"default": "not-consulted",
"title": "Outcome",
"type": "string"
},
"detail": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
],
"default": null,
"title": "Detail"
}
},
"title": "AIReport",
"type": "object"
},
"Diagnostic": {
"description": "A correctness problem found in the code.",
"properties": {
"severity": {
"$ref": "#/$defs/Severity"
},
"rule": {
"title": "Rule",
"type": "string"
},
"message": {
"title": "Message",
"type": "string"
},
"line": {
"anyOf": [
{
"type": "integer"
},
{
"type": "null"
}
],
"default": null,
"title": "Line"
},
"column": {
"anyOf": [
{
"type": "integer"
},
{
"type": "null"
}
],
"default": null,
"title": "Column"
}
},
"required": [
"severity",
"rule",
"message"
],
"title": "Diagnostic",
"type": "object"
},
"Meta": {
"description": "Provenance of a response, so results stay reproducible.",
"properties": {
"service": {
"title": "Service",
"type": "string"
},
"version": {
"title": "Version",
"type": "string"
},
"api": {
"default": "v1",
"title": "Api",
"type": "string"
},
"engine": {
"additionalProperties": {
"type": "string"
},
"title": "Engine",
"type": "object"
},
"ai": {
"anyOf": [
{
"$ref": "#/$defs/AIReport"
},
{
"type": "null"
}
],
"default": null
},
"mode": {
"$ref": "#/$defs/Mode",
"default": "static"
},
"duration_ms": {
"default": 0,
"title": "Duration Ms",
"type": "integer"
},
"request_id": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
],
"default": null,
"title": "Request Id"
}
},
"required": [
"service",
"version"
],
"title": "Meta",
"type": "object"
},
"Mode": {
"description": "How much work the service is allowed to do.\n\n``static``\n Never executes the submitted code. Parsing, linting and security\n scanning only. This is the default and the only mode that is safe to\n expose without a container sandbox.\n``repair``\n Static mode plus deterministic auto-fixes and refactors.\n``execute``\n Repair plus running the code inside a sandbox to prove it works.",
"enum": [
"static",
"repair",
"execute"
],
"title": "Mode",
"type": "string"
},
"RuntimeReport": {
"description": "Outcome of executing the code in a sandbox.",
"properties": {
"ran": {
"default": false,
"title": "Ran",
"type": "boolean"
},
"returncode": {
"anyOf": [
{
"type": "integer"
},
{
"type": "null"
}
],
"default": null,
"title": "Returncode"
},
"stdout": {
"default": "",
"title": "Stdout",
"type": "string"
},
"stderr": {
"default": "",
"title": "Stderr",
"type": "string"
},
"duration_ms": {
"anyOf": [
{
"type": "integer"
},
{
"type": "null"
}
],
"default": null,
"title": "Duration Ms"
},
"timed_out": {
"default": false,
"title": "Timed Out",
"type": "boolean"
},
"sandbox": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
],
"default": null,
"title": "Sandbox"
}
},
"title": "RuntimeReport",
"type": "object"
},
"SecurityFinding": {
"description": "A security problem reported by one of the scanners.",
"properties": {
"tool": {
"title": "Tool",
"type": "string"
},
"id": {
"title": "Id",
"type": "string"
},
"severity": {
"$ref": "#/$defs/Severity"
},
"confidence": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
],
"default": null,
"title": "Confidence"
},
"message": {
"title": "Message",
"type": "string"
},
"line": {
"anyOf": [
{
"type": "integer"
},
{
"type": "null"
}
],
"default": null,
"title": "Line"
},
"cwe": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
],
"default": null,
"title": "Cwe"
}
},
"required": [
"tool",
"id",
"severity",
"message"
],
"title": "SecurityFinding",
"type": "object"
},
"Severity": {
"description": "Severity of a single finding.",
"enum": [
"error",
"warning",
"info"
],
"title": "Severity",
"type": "string"
}
},
"description": "The result an agent gets back and pays for.",
"title": "ValidateResponse"
}🟡execute_python(code, language, options)
Everything repair does, and then RUNS the code in a throwaway container — no network, read-only filesystem, killed at options.timeout_s — reporting exit code, stdout and stderr. Any '>>>' examples in the code are run too, and one that does not print what it says is an error the other tools cannot see. This is a side effect: do not submit code you do not want executed. Use it when you need proof that the code runs, or that it does what it says. Alternatives: validate_python for the diagnosis and repair_python for the fix, neither of which runs anything. Auth: a key is required. This call needs a paid key and answers HTTP 402 without one. Credits are bought without an account, 10 per call: GET /v1/pricing says where to send the xDAI. Or pay for this one call with no key at all: call it without one and the result carries x402 payment requirements ($0.1 in USD Coin on eip155:8453); sign them and repeat the call with the payment in _meta['x402/payment']. Arguments: code: the whole file, 1..200000 bytes of UTF-8 measured after encoding (empty is refused with 400, larger with 413); a fragment is fine, but line and column numbers in the answer count from 1 in what you sent. language: must be 'python'; anything else is 400, and the field may be omitted. options.max_iterations (1..10, default 3) caps the fix/verify rounds: raise it for a file with several independent faults, leave it for a snippet. options.optimize (default false) additionally folds constants and drops dead code, and is only worth setting when you asked for a rewrite anyway. options.transpile_to (e.g. 'javascript') returns a translation of the *repaired* source in transpiled, not of what you sent. fixed_code is null when nothing could be proven safe to change, so treat null as 'no fix', not as an error. options.timeout_s (seconds, default 5) is the wall clock for the run; the schema allows up to 60 but this deployment caps it at 30 and refuses a larger value with 400. options.expected_output compares stdout byte for byte and adds an 'expected-output' diagnostic (valid=false) when it differs, which is how you ask for 'it did the right thing' rather than 'it ran'. options.examples is the same question for code with no output: pass what you asked for as doctest lines ('>>> total([1, 2])' then '3') or assertions ('assert total([1, 2]) == 3'), and each is run against the code -- one that does not hold is a 'python:example-mismatch' error, and repair looks for a single-token change that makes them all pass. Send it whenever you know what you asked for: without it, code that runs but returns the wrong answer looks perfect from here. The program that runs is the repaired one, so read fixed_code before you trust runtime.stdout, and it runs exactly once however many rounds the repair took. Returns valid, score 0..1, diagnostics (rule, message, line, column), security findings, fixes, fixed_code and runtime; see outputSchema. The code and its verdict are retained to improve the service.
输入模式
{
"type": "object",
"properties": {
"code": {
"description": "The source to check, as a whole file where possible: diagnostics carry the line and column of the text you send, and a fragment hides the imports and definitions the type check needs. A deployment may accept fewer bytes than the 200000 here.",
"maxLength": 200000,
"minLength": 1,
"title": "Code",
"type": "string"
},
"language": {
"$ref": "#/$defs/Language",
"default": "python",
"description": "The language of the code. A service that does not handle it refuses the request rather than guessing; the enum is shared across services, so it lists more than any one of them accepts."
},
"options": {
"$ref": "#/$defs/Options",
"description": "Tuning knobs. Most of them only take effect in the mode that does the corresponding work; see each field."
}
},
"required": [
"code"
],
"$defs": {
"Language": {
"description": "Source languages a validator can accept.",
"enum": [
"python",
"javascript",
"typescript",
"html",
"sql",
"solidity",
"other"
],
"title": "Language",
"type": "string"
},
"Mode": {
"description": "How much work the service is allowed to do.\n\n``static``\n Never executes the submitted code. Parsing, linting and security\n scanning only. This is the default and the only mode that is safe to\n expose without a container sandbox.\n``repair``\n Static mode plus deterministic auto-fixes and refactors.\n``execute``\n Repair plus running the code inside a sandbox to prove it works.",
"enum": [
"static",
"repair",
"execute"
],
"title": "Mode",
"type": "string"
},
"Options": {
"description": "Per-request tuning knobs.",
"properties": {
"timeout_s": {
"anyOf": [
{
"exclusiveMinimum": 0,
"maximum": 60,
"type": "number"
},
{
"type": "null"
}
],
"default": null,
"description": "Wall-clock budget for running the code. Omitted means the service's own default (MSVC_DEFAULT_TIMEOUT_S). Only execute mode runs anything; a deployment may cap this below the 60 the schema allows and refuses a larger value.",
"title": "Timeout S"
},
"max_iterations": {
"default": 3,
"description": "How many fix/verify rounds the repair loop may take. Ignored in static mode, which changes nothing.",
"maximum": 10,
"minimum": 1,
"title": "Max Iterations",
"type": "integer"
},
"transpile_to": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
],
"default": null,
"description": "Target language for a transpiled copy, e.g. 'javascript'. The copy is made from the code as it ends up, so in repair and execute mode it translates the repaired source rather than the submitted one.",
"title": "Transpile To"
},
"expected_output": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
],
"default": null,
"description": "Exact stdout the code must produce in execute mode. A mismatch is an 'expected-output' diagnostic and makes the response invalid, even when the program exits cleanly. Ignored in the other modes, which produce no output.",
"title": "Expected Output"
},
"examples": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
],
"default": null,
"description": "What the code is supposed to do, as doctest lines ('>>> f(2)' on one line, '4' on the next) or as plain assertions ('assert f(2) == 4'). In execute mode they are run in the sandbox: an example that does not hold is a 'python:example-mismatch' error and makes the response invalid, and repair searches for a single-token change that makes every one of them pass. This is the only way the service can tell code that runs from code that is right, so send it whenever you know what you asked for. Examples already written in the code ('>>> ' in any string) are used the same way without this option. Ignored in the other modes, which run nothing.",
"title": "Examples"
},
"optimize": {
"default": false,
"description": "Run constant folding / dead-code elimination. Off by default: the optimiser rewrites the program, and a rewrite is only returned when it provably keeps every effectful construct.",
"title": "Optimize",
"type": "boolean"
}
},
"title": "Options",
"type": "object"
}
},
"description": "A validation job submitted by an agent.",
"title": "ValidateRequest"
}输出模式
{
"type": "object",
"properties": {
"valid": {
"title": "Valid",
"type": "boolean"
},
"score": {
"maximum": 1,
"minimum": 0,
"title": "Score",
"type": "number"
},
"diagnostics": {
"items": {
"$ref": "#/$defs/Diagnostic"
},
"title": "Diagnostics",
"type": "array"
},
"security": {
"items": {
"$ref": "#/$defs/SecurityFinding"
},
"title": "Security",
"type": "array"
},
"fixes": {
"items": {
"type": "string"
},
"title": "Fixes",
"type": "array"
},
"fixed_code": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
],
"default": null,
"title": "Fixed Code"
},
"transpiled": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
],
"default": null,
"title": "Transpiled"
},
"runtime": {
"$ref": "#/$defs/RuntimeReport"
},
"meta": {
"$ref": "#/$defs/Meta"
}
},
"required": [
"valid",
"score",
"meta"
],
"$defs": {
"AIReport": {
"description": "What the optional AI refinement backend contributed.\n\nAbsent from a response when no backend is configured. Present but with\n``consulted=False`` when the deterministic fixers settled the code on their\nown, so a caller can tell \"the model was never needed\" apart from \"the\nmodel was asked and came back empty-handed\".",
"properties": {
"consulted": {
"default": false,
"title": "Consulted",
"type": "boolean"
},
"backend": {
"default": "",
"title": "Backend",
"type": "string"
},
"calls": {
"default": 0,
"title": "Calls",
"type": "integer"
},
"duration_ms": {
"default": 0,
"title": "Duration Ms",
"type": "integer"
},
"outcome": {
"default": "not-consulted",
"title": "Outcome",
"type": "string"
},
"detail": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
],
"default": null,
"title": "Detail"
}
},
"title": "AIReport",
"type": "object"
},
"Diagnostic": {
"description": "A correctness problem found in the code.",
"properties": {
"severity": {
"$ref": "#/$defs/Severity"
},
"rule": {
"title": "Rule",
"type": "string"
},
"message": {
"title": "Message",
"type": "string"
},
"line": {
"anyOf": [
{
"type": "integer"
},
{
"type": "null"
}
],
"default": null,
"title": "Line"
},
"column": {
"anyOf": [
{
"type": "integer"
},
{
"type": "null"
}
],
"default": null,
"title": "Column"
}
},
"required": [
"severity",
"rule",
"message"
],
"title": "Diagnostic",
"type": "object"
},
"Meta": {
"description": "Provenance of a response, so results stay reproducible.",
"properties": {
"service": {
"title": "Service",
"type": "string"
},
"version": {
"title": "Version",
"type": "string"
},
"api": {
"default": "v1",
"title": "Api",
"type": "string"
},
"engine": {
"additionalProperties": {
"type": "string"
},
"title": "Engine",
"type": "object"
},
"ai": {
"anyOf": [
{
"$ref": "#/$defs/AIReport"
},
{
"type": "null"
}
],
"default": null
},
"mode": {
"$ref": "#/$defs/Mode",
"default": "static"
},
"duration_ms": {
"default": 0,
"title": "Duration Ms",
"type": "integer"
},
"request_id": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
],
"default": null,
"title": "Request Id"
}
},
"required": [
"service",
"version"
],
"title": "Meta",
"type": "object"
},
"Mode": {
"description": "How much work the service is allowed to do.\n\n``static``\n Never executes the submitted code. Parsing, linting and security\n scanning only. This is the default and the only mode that is safe to\n expose without a container sandbox.\n``repair``\n Static mode plus deterministic auto-fixes and refactors.\n``execute``\n Repair plus running the code inside a sandbox to prove it works.",
"enum": [
"static",
"repair",
"execute"
],
"title": "Mode",
"type": "string"
},
"RuntimeReport": {
"description": "Outcome of executing the code in a sandbox.",
"properties": {
"ran": {
"default": false,
"title": "Ran",
"type": "boolean"
},
"returncode": {
"anyOf": [
{
"type": "integer"
},
{
"type": "null"
}
],
"default": null,
"title": "Returncode"
},
"stdout": {
"default": "",
"title": "Stdout",
"type": "string"
},
"stderr": {
"default": "",
"title": "Stderr",
"type": "string"
},
"duration_ms": {
"anyOf": [
{
"type": "integer"
},
{
"type": "null"
}
],
"default": null,
"title": "Duration Ms"
},
"timed_out": {
"default": false,
"title": "Timed Out",
"type": "boolean"
},
"sandbox": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
],
"default": null,
"title": "Sandbox"
}
},
"title": "RuntimeReport",
"type": "object"
},
"SecurityFinding": {
"description": "A security problem reported by one of the scanners.",
"properties": {
"tool": {
"title": "Tool",
"type": "string"
},
"id": {
"title": "Id",
"type": "string"
},
"severity": {
"$ref": "#/$defs/Severity"
},
"confidence": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
],
"default": null,
"title": "Confidence"
},
"message": {
"title": "Message",
"type": "string"
},
"line": {
"anyOf": [
{
"type": "integer"
},
{
"type": "null"
}
],
"default": null,
"title": "Line"
},
"cwe": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
],
"default": null,
"title": "Cwe"
}
},
"required": [
"tool",
"id",
"severity",
"message"
],
"title": "SecurityFinding",
"type": "object"
},
"Severity": {
"description": "Severity of a single finding.",
"enum": [
"error",
"warning",
"info"
],
"title": "Severity",
"type": "string"
}
},
"description": "The result an agent gets back and pays for.",
"title": "ValidateResponse"
}社区
证据