Building with AI

Orca Security cuts LLM costs by 90% with multi-stage Bedrock pipeline

Orca Security reduced query latency and token usage by building a nine-stage natural language agent on Amazon Bedrock that converts plain text into structured security queries.

Illustration of a multi-stage filtering pipeline transforming unstructured text into structured data blocks.
Illustration generated for this article

Orca Security partnered with AWS to launch Discovery AI, a natural language interface for its Sonar security platform. Released in October 2026, the system allows analysts to query complex cloud infrastructure data using plain English instead of specialized syntax. The solution runs on Amazon Bedrock and significantly lowers operational costs while improving response times.

What happened

Security analysts at Orca Security faced a steep learning curve when querying their Sonar platform. Sonar tracks over 900 cloud resource models, including Amazon EC2 instances and S3 buckets. To extract specific insights, users had to construct precise JSON objects, navigate nested parent-child hierarchies, and select from 18 different comparison operators. This process required deep familiarity with the underlying schema, creating a barrier for many users who needed fast answers about their cloud environment.

The initial proof of concept attempted to solve this by loading the entire Sonar schema into a single prompt for the largest available large language model. While internal users and design partners praised the output quality, the approach proved unsustainable at scale. Each workload consumed approximately 2 million input tokens, resulting in high costs. Latency averaged 60 seconds per request, and accuracy suffered on complex queries involving multiple models or conditions. The team needed a production-ready architecture that balanced speed, cost, and precision.

To address these challenges, Orca engineered Discovery AI as a hybrid pipeline on Amazon Bedrock. The new system combines Retrieval Augmented Generation (RAG) with schema-aware query construction. By breaking the task into nine distinct stages and assigning specific foundation models to each step, Orca achieved a 90 percent reduction in query costs, a 93 percent drop in input tokens, and a 75 percent decrease in latency. Responses now arrive in roughly 15 seconds, making the tool viable for daily use by thousands of analysts.

How it works

Discovery AI operates as a multi-stage pipeline that converts natural language requests into valid Sonar filters. The process begins with context setup, where the system ingests the user’s question along with metadata about their organization and connected cloud providers. A deterministic matcher then checks for structured inputs like IP addresses, CVEs, or ARNs using regex rules. If a high-confidence pattern is found, the system returns a predefined filter immediately, bypassing expensive LLM inference entirely.

If no direct match exists, the request passes through an LLM guardrail that screens for safety and relevance, blocking prompt injections or off-topic queries. The system then uses Amazon Titan Text Embeddings to retrieve the 20 most semantically similar historical query examples from a vector store. Cohere Rerank 3.5 refines this list to the top five most relevant examples. If an exact match is found among these, the known-good filter is reused. Otherwise, the pipeline proceeds to generative construction.

A model selection step narrows the 900+ available Sonar models down to a small, relevant subset based on the user’s request and retrieved examples. This reduced context is passed to an agentic generator powered by Anthropic Claude Haiku 4.5. The agent constructs the final filter, iteratively refining it based on static and API-backed validation. If validation fails, the error is fed back to the agent for correction, ensuring the final output is syntactically and semantically correct before being returned to the user.

Key details

  • Orca Security reduced input tokens by 93 percent and query costs by 90 percent compared to the initial baseline.
  • End-to-end latency dropped from 60 seconds to approximately 15 seconds per workload.
  • The pipeline consists of nine stages, including deterministic matching, guardrails, semantic retrieval, and agentic generation.
  • Amazon Nova 2 Lite handles low-cost tasks like guardrails and validation, while Anthropic Claude Haiku 4.5 manages complex reasoning and generation.
  • The system supports over 900 cloud infrastructure models and 18 comparison operators within the Sonar query language.
  • Validation is both static and API-backed, allowing the agent to self-correct errors before returning a result.

Why it matters

For engineering teams building AI agents, this case study demonstrates the importance of decomposing complex tasks into specialized stages. Trying to force a single large model to handle context retrieval, reasoning, and formatting often leads to inefficiency and hallucinations. By routing simple patterns through deterministic logic and reserving LLMs for ambiguous reasoning, developers can drastically reduce token consumption. This hybrid approach ensures that expensive computational resources are only used when necessary, making AI features economically viable at scale.

The architecture also highlights the value of right-sizing models for specific sub-tasks. Using a lightweight model for guardrails and validation, while reserving a more capable model for generation, optimizes both cost and performance. This strategy allows teams to maintain high accuracy without incurring the latency penalties associated with monolithic prompts. As AI integration becomes standard in enterprise software, such modular designs will be critical for maintaining responsive and cost-effective user experiences.

What you can do

  • Audit your current LLM pipelines to identify stages that can be handled by deterministic rules or smaller models.
  • Implement a guardrail layer early in your pipeline to filter out unsafe or irrelevant requests before they reach generative models.
  • Use embedding-based retrieval to fetch relevant examples or schema fragments, reducing the context window required for generation.
  • Add a validation step that feeds errors back to the agent, enabling self-correction rather than accepting invalid outputs.
  • Evaluate multi-model orchestration platforms like Amazon Bedrock to simplify integration and allow flexible model swapping.
  • Monitor token usage and latency per stage to identify bottlenecks and optimize model allocation for cost efficiency.
  • #aws
  • #llm ops
  • #security
  • #rag
  • #cloud infrastructure

Tools from the Bytechap store

$89

DocBento

Self-hosted document management that reads every scan and answers with page citations.

Live demo

Keep reading

All stories