Converting Natural Language to Structured GraphQL Queries Using LLMs

cato_networks · Tech · 2025 · source Agentic: no · promotional bias: med · source-backed · extracted with prompt 0.5.6 (schema v2)

Generated from extraction.json — do not edit by hand. Every claim cites verbatim source evidence; stated means the quote directly asserts the claim, implied means it supports it indirectly.

Problem

Domain: SASE event search

Cato Networks needed to make its SASE Events page usable for customers who did not know the product glossary or manual filter syntax. The page can contain millions of events over a selected time range, and users needed natural-language search that still produced valid, API-compatible filters.

Constraints:

Architecture

Cato built a natural-language search service on Amazon EKS that prompts Claude 3.5 Sonnet through Amazon Bedrock to emit JSON conforming to an IETF JSON schema, validates the response, applies failure policies, and deterministically translates valid structured output into GraphQL API requests for the Events page.

Diagram confidence: explicit (topology described by the source).

flowchart LR
  management-console["Management console"] --> natural-language-search-service["Natural language search service"]
  natural-language-search-service --> amazon-bedrock["Amazon Bedrock"]
  amazon-bedrock --> claude-35-sonnet["Claude 35 Sonnet"]
  natural-language-search-service --> json-schema-validator["JSON schema validator"]
  json-schema-validator --> natural-language-search-service
  natural-language-search-service --> graphql-server["GraphQL server"]
  benchmark-suite["Benchmark suite"] --> amazon-bedrock
  benchmark-suite --> claude-35-sonnet
Drag to pan · scroll or use +/− to zoom · reconstructed from the source's described component topology

Components

Component Role Interacts with
Management console Events-page UI where users submit free-text event searches. Natural language search service
Natural language search service EKS-hosted bridge that creates prompts, calls Bedrock, validates JSON, and translates outputs to GraphQL. Management console, Amazon Bedrock, JSON schema validator, GraphQL server
Amazon Bedrock Managed FM serving layer used to benchmark and call Claude 3.5 Sonnet. Natural language search service, Claude 35 Sonnet
Claude 35 Sonnet Selected foundation model that converts free text into structured JSON filters. Amazon Bedrock
JSON schema validator Checks model output against the expected schema and produces failure or warning policies. Natural language search service
GraphQL server Backend API that executes structured event queries for a Cato account. Natural language search service
Benchmark suite Hundreds of text queries and expected JSON outputs used to select the FM and gate release. Amazon Bedrock, Claude 35 Sonnet

Data flow

A user enters free text in the management console. The Natural Language Search service builds a prompt with the JSON schema and product-specific instructions, sends it to Claude 3.5 Sonnet on Bedrock, validates the JSON response against the same schema, handles violations with warnings or failures, converts valid filters into GraphQL, and queries the GraphQL server.

“Instead of asking the FM to generate the GraphQL API request directly, we can use the following method:”article, stated
“After the FM successfully translates the free text into structured output, converting it into an API request—such as GraphQL—is a straightforward and deterministic process.”article, stated

Why this architecture

Cato deliberately put a schema-valid JSON layer between natural language and GraphQL. That made model output easy to validate and allowed deterministic API translation while Bedrock made model benchmarking and swapping practical.

“Given the extensive number of instructions and limitations, we can’t trust the model output without checking the results for validity.”article, stated
“Amazon Bedrock enabled us to efficiently transition between different models, making it simple to benchmark and optimize for accuracy, latency, and cost”article, stated

Models used: anthropic.claude-3-5-sonnet-20241022-v2:0 · Foundation models available through Amazon Bedrock

Scale

Alternatives considered (roads not taken)

Manual event filtering

Rejected because: It is time-consuming and requires deep product glossary knowledge.

“the process of adding filters to the search query is manual and can be time consuming, because it requires in-depth familiarity with the product glossary.”article, stated

Have the model generate GraphQL directly

Rejected because: Direct GraphQL generation would be harder to validate safely than JSON schema output.

“Instead of asking the FM to generate the GraphQL API request directly, we can use the following method:”article, stated

Use prompt engineering forever for complex schemas

Rejected because: Including the full schema in every prompt can create a high token count, so fine-tuning may reduce cost later.

“Including the entire schema in the prompt can lead to a significantly high token count for a single query.”article, stated

Patterns

structured-output-contract (output)

The prompt requires JSON output validated against an IETF JSON schema before API translation.

“Your task is to convert free text queries to a JSON format that will be used to query security and network events in a SASE management console of Cato Networks.”article, stated

eval-driven-development (evaluation)

Cato benchmarked models with expected JSON outputs and release-gated on an error-rate criterion.

“Using our benchmark, we evaluated several FMs on Amazon Bedrock, taking into account accuracy, latency, and cost.”article, stated

model-routing (model-selection)

Bedrock let Cato transition between models and choose the one meeting accuracy, latency, and cost needs.

“Based on the results, we selected anthropic.claude-3-5-sonnet-20241022-v2:0”article, stated

Tradeoffs

Use JSON schema as the intermediate representation

Chose validated JSON then deterministic GraphQL over direct GraphQL from the model.

Rationale: The schema can validate model output and identify exact violations before hitting the product API.

“In addition to validating alignment, the JSON schema can also point out the exact schema violation.”article, stated

Use prompt engineering rather than fine-tuning initially

Chose schema-rich prompt through Bedrock over custom model fine-tuning.

Rationale: The prompt solution met the error criterion, though the authors note fine-tuning could reduce cost for complex schemas.

“Although a prompt engineering solution met our needs, users handling complex JSON schemas might want to explore alternative approaches to reduce costs.”article, stated

Gotchas (what bit them)

Schema violations can break product functionality.

Root cause: Model behavior is non-deterministic and may generate unsupported keys or invalid filter formats.

Resolution: Validate JSON against the schema and apply policies by failure type.

“model behavior is inherently non-deterministic, and responses that don’t comply with our API will break the product functionality.”article, stated

Translation failures create poor user experience.

Root cause: Invalid JSON or invalid schema output cannot become a useful event query.

Resolution: Gate release on low error rate and return warnings/failures based on validation results.

“Because translation failures lead to a poor user experience, releasing the feature was contingent on achieving an error rate below 0.05”article, stated

Evaluation

Cato benchmarked foundation models on hundreds of text queries with expected JSON outputs, classifying responses as success, partial, or error.

Metrics: Valid JSON · Valid by schema · Full filter match · Partial filter match · Invalid JSON/schema error rate · Latency · Cost

“Because translation failures lead to a poor user experience, releasing the feature was contingent on achieving an error rate below 0.05”article, stated

Outcomes

The feature targets Events pages with potentially millions of events and was benchmarked against hundreds of expected-query examples.

“significant reduction in query time—cut down from minutes of manual filtering to near-instant results.”article, stated
“Account admins using the new feature have reported near-zero time to value”article, stated