Skip to content

Conversation

@icecrasher321
Copy link
Collaborator

Summary

Should not ignore when tools are unused but active.

Type of Change

  • Bug fix

Testing

Tested manually.

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

@vercel
Copy link

vercel bot commented Jan 28, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Review Updated (UTC)
docs Skipped Skipped Jan 28, 2026 3:40am

Request Review

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Jan 28, 2026

Greptile Overview

Greptile Summary

Fixed a logic bug in the OpenRouter provider where structured output formatting (responseFormat) was incorrectly skipped when tools were configured but not invoked by the model.

Key Changes:

  • Removed the toolCalls.length > 0 condition from line 519, changing the logic to apply responseFormat whenever tools are active, regardless of whether they were actually called

Impact:

  • Previously, if tools were configured (hasActiveTools = true) but the model chose not to use them (toolCalls.length = 0), the final structured output request would be skipped
  • This fix ensures responseFormat is properly applied in the final response when tools are available but unused

Confidence Score: 5/5

  • This PR is safe to merge with no risk
  • The change is a simple, correct bug fix that removes an overly restrictive condition. The logic is sound: responseFormat should be applied when tools are configured (hasActiveTools), regardless of whether the model actually invoked them. The fix aligns with the intended behavior and has been manually tested.
  • No files require special attention

Important Files Changed

Filename Overview
apps/sim/providers/openrouter/index.ts Fixed logic bug where responseFormat was skipped when tools were configured but unused

Sequence Diagram

sequenceDiagram
    participant Client
    participant OpenRouterProvider
    participant OpenAI_API as OpenRouter API
    participant Tools

    Client->>OpenRouterProvider: executeRequest(request with tools & responseFormat)
    OpenRouterProvider->>OpenRouterProvider: prepareToolsWithUsageControl()
    OpenRouterProvider->>OpenRouterProvider: hasActiveTools = true
    
    OpenRouterProvider->>OpenAI_API: Initial API call with tools
    OpenAI_API-->>OpenRouterProvider: Response (no tool calls)
    
    Note over OpenRouterProvider: toolCalls.length = 0<br/>(model didn't use tools)
    
    alt OLD BEHAVIOR (Bug)
        OpenRouterProvider->>OpenRouterProvider: Check: hasActiveTools && toolCalls.length > 0
        Note over OpenRouterProvider: Condition FALSE<br/>Skip responseFormat
        OpenRouterProvider-->>Client: Return without structured output
    end
    
    alt NEW BEHAVIOR (Fixed)
        OpenRouterProvider->>OpenRouterProvider: Check: hasActiveTools
        Note over OpenRouterProvider: Condition TRUE<br/>Apply responseFormat
        OpenRouterProvider->>OpenAI_API: Final call with responseFormat
        OpenAI_API-->>OpenRouterProvider: Structured JSON response
        OpenRouterProvider-->>Client: Return with structured output
    end
Loading

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No files reviewed, no comments

Edit Code Review Agent Settings | Greptile

@icecrasher321 icecrasher321 merged commit 500dcd4 into staging Jan 28, 2026
7 checks passed
@waleedlatif1 waleedlatif1 deleted the fix/openrouter-resp-format branch January 28, 2026 07:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants