Problem
All five providers (OpenAI, Anthropic, Cerebras, Cloudflare, Groq) blindly map tool_calls from API responses into ToolCall[] with zero runtime validation:
toolCalls = choice.message.tool_calls.map(tc => ({
id: tc.id,
type: 'function' as const,
function: { name: tc.function.name, arguments: tc.function.arguments }
}));
TypeScript interfaces provide compile-time shape checks, but at runtime nothing validates:
tc.id exists and is a string
tc.function.name is a non-empty string
tc.function.arguments is valid/parseable JSON (providers sometimes return malformed JSON)
- The tool name matches one of the tools sent in the request
This is a system boundary (external API responses) where validation is warranted per OWASP input validation guidance.
Impact
A malformed tool_calls entry (missing id, garbage arguments, hallucinated tool name) propagates to the caller unchecked. Downstream consumers (e.g. AEGIS dispatch) would fail with opaque errors or silently pass bad data.
Affected files
src/providers/openai.ts (line ~358)
src/providers/anthropic.ts (line ~426)
src/providers/cerebras.ts (line ~382)
src/providers/cloudflare.ts (line ~493)
src/providers/groq.ts (line ~378)
Suggested approach
- Add a shared
validateToolCalls(raw, requestedTools?) helper in src/utils/ or src/providers/base.ts
- Validate shape:
id is string, function.name is non-empty string, function.arguments is string
- Optionally validate
arguments is parseable JSON (warn or strip if not)
- Optionally validate tool name is in the set of requested tools (warn if not)
- Call from each provider's
formatResponse before returning
Problem
All five providers (OpenAI, Anthropic, Cerebras, Cloudflare, Groq) blindly map
tool_callsfrom API responses intoToolCall[]with zero runtime validation:TypeScript interfaces provide compile-time shape checks, but at runtime nothing validates:
tc.idexists and is a stringtc.function.nameis a non-empty stringtc.function.argumentsis valid/parseable JSON (providers sometimes return malformed JSON)This is a system boundary (external API responses) where validation is warranted per OWASP input validation guidance.
Impact
A malformed
tool_callsentry (missingid, garbagearguments, hallucinated tool name) propagates to the caller unchecked. Downstream consumers (e.g. AEGIS dispatch) would fail with opaque errors or silently pass bad data.Affected files
src/providers/openai.ts(line ~358)src/providers/anthropic.ts(line ~426)src/providers/cerebras.ts(line ~382)src/providers/cloudflare.ts(line ~493)src/providers/groq.ts(line ~378)Suggested approach
validateToolCalls(raw, requestedTools?)helper insrc/utils/orsrc/providers/base.tsidis string,function.nameis non-empty string,function.argumentsis stringargumentsis parseable JSON (warn or strip if not)formatResponsebefore returning