Skip to main content

validate_request

Function validate_request 

Source
pub fn validate_request(
    capabilities: &BackendCapabilities,
    supported_languages: &[ExecutionLanguage],
    request: &ExecutionRequest,
) -> Result<(), ExecutionError>
Expand description

Validates a full execution request against a backend’s capabilities.

Checks that:

  1. The backend supports the requested language
  2. The payload type matches the language (e.g., GuestModule only for Wasm)
  3. The sandbox policy is enforceable by the backend

Call this before CodeExecutor::execute for clear, early errors.

§Example

use adk_code::{
    BackendCapabilities, ExecutionIsolation, ExecutionLanguage,
    ExecutionPayload, ExecutionRequest, SandboxPolicy,
    validate_request,
};

let caps = BackendCapabilities {
    isolation: ExecutionIsolation::ContainerEphemeral,
    enforce_network_policy: true,
    enforce_filesystem_policy: true,
    enforce_environment_policy: true,
    enforce_timeout: true,
    supports_structured_output: true,
    supports_process_execution: false,
    supports_persistent_workspace: false,
    supports_interactive_sessions: false,
};

let request = ExecutionRequest {
    language: ExecutionLanguage::Rust,
    payload: ExecutionPayload::Source {
        code: "fn run(input: serde_json::Value) -> serde_json::Value { input }".to_string(),
    },
    argv: vec![],
    stdin: None,
    input: None,
    sandbox: SandboxPolicy::strict_rust(),
    identity: None,
};

let supported = [ExecutionLanguage::Rust];
assert!(validate_request(&caps, &supported, &request).is_ok());