A framework for efficient and secure LLM agency: a case for the GraphQL paradigm
Abstract
LLM agents must translate natural language into concrete actions on external tools. Most systems use JSON-based function calling or, more riskily, let models emit imperative code. We propose a GraphQL-first alternative that reframes tool use as typed, declarative program synthesis against a schema. This yields three measurable advantages. First, efficiency: a token–economy analysis shows that a single GraphQL query replaces multiple RPC calls, reducing request tokens from 63 to 32 and total operational tokens from 245 to 175 in a representative user–orders task. Second, reliability: schema validation provides deterministic, structured error diagnostics that enable self-correcting interaction loops without bespoke prompt engineering. Third, security: the schema- bounded language forms a native sandbox that eliminates arbitrary code execution pathways and reduces prompt-injection impact to a bounded query surface governed by depth/complexity limits and authorization. Because GraphQL is standardized and widely understood by general coding LLMs, the approach is model-agnostic and interoperable. We argue that GraphQL constitutes a principled, testable alternative to function calling for agentic systems, combining lower cost, stronger safety, and improved cognitive robustness.