fix: don't zod check ai gateway on no_mapping#5099
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub. 3 Skipped Deployments
|
|
Claude finished @connortbot's task —— View job Code Review AnalysisTodo List:
Review SummaryScore: 7/10 - Good change with sound logic, but needs documentation and test coverage AnalysisThe change adds a condition to skip OpenAI payload validation when File: // Before
if (attempt.authType === "ptb") {
// After
if (attempt.authType === "ptb" && this.requestWrapper.heliconeHeaders.gatewayConfig.bodyMapping !== "NO_MAPPING") {Detailed Feedback✅ Positive Aspects
|
There was a problem hiding this comment.
Greptile Overview
Summary
Fixes validation logic to skip OpenAI schema validation when NO_MAPPING body mapping is configured. When users set the Helicone-Gateway-Body-Mapping: NO_MAPPING header, they're sending requests in the provider's native format (e.g., Anthropic format) rather than OpenAI format. The previous code would incorrectly validate these native-format requests against the OpenAI schema, causing validation errors for valid requests.
- Prevents false validation errors when using provider-native request formats
- Maintains validation for OpenAI-formatted requests
- Aligns validation behavior with response mapping logic (which already respects
NO_MAPPING)
Confidence Score: 5/5
- This PR is safe to merge with minimal risk
- The change is a simple, logical fix that adds an appropriate condition check. It addresses a clear bug where OpenAI validation was incorrectly applied to non-OpenAI request formats. The fix is consistent with existing
NO_MAPPINGhandling in the response mapping logic (line 351-353). The condition is straightforward and doesn't introduce any edge cases or race conditions. - No files require special attention
Important Files Changed
File Analysis
| Filename | Score | Overview |
|---|---|---|
| worker/src/lib/ai-gateway/SimpleAIGateway.ts | 5/5 | Added condition to skip OpenAI payload validation when NO_MAPPING is configured, preventing validation errors for non-OpenAI request formats |
Sequence Diagram
sequenceDiagram
participant Client
participant SimpleAIGateway
participant validateOpenAIChatPayload
participant AttemptExecutor
participant Provider
Client->>SimpleAIGateway: Request with NO_MAPPING header
Note over SimpleAIGateway: Parse request body
SimpleAIGateway->>SimpleAIGateway: Build attempts (ptb auth)
alt bodyMapping == "NO_MAPPING"
Note over SimpleAIGateway: Skip OpenAI validation
SimpleAIGateway->>AttemptExecutor: Execute attempt with native format
else bodyMapping == "OPENAI"
SimpleAIGateway->>validateOpenAIChatPayload: Validate OpenAI schema
alt Validation fails
validateOpenAIChatPayload-->>SimpleAIGateway: Error
SimpleAIGateway->>Client: Return validation error
else Validation succeeds
validateOpenAIChatPayload-->>SimpleAIGateway: OK
SimpleAIGateway->>AttemptExecutor: Execute attempt
end
end
AttemptExecutor->>Provider: Forward request
Provider-->>AttemptExecutor: Response
AttemptExecutor-->>SimpleAIGateway: Response
alt bodyMapping == "NO_MAPPING"
Note over SimpleAIGateway: Return response without mapping
else bodyMapping == "OPENAI"
Note over SimpleAIGateway: Map response to OpenAI format
end
SimpleAIGateway-->>Client: Final response
1 file reviewed, no comments
No description provided.