Skip to content

[doximity] add more info for error response type mismatch#197

Merged
vivek-athina merged 3 commits intomainfrom
cody/doximity-error-response-type-mismatch
Apr 24, 2025
Merged

[doximity] add more info for error response type mismatch#197
vivek-athina merged 3 commits intomainfrom
cody/doximity-error-response-type-mismatch

Conversation

@codyathina
Copy link
Contributor

@codyathina codyathina commented Apr 24, 2025

Summary by CodeRabbit

  • Bug Fixes
    • Improved error messages for LLM response issues by including the actual response type and a preview of the response content, making it easier to diagnose problems.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Apr 24, 2025

Walkthrough

The update enhances error messages within the PromptExecution class by appending additional context to error outputs in the execute, execute_async, and execute_stream methods. Specifically, when a type mismatch or invalid response format is detected from the LLM service, the error message now includes the actual runtime type of the response and a truncated preview of its content (up to 300 characters). No changes were made to method signatures or class interfaces; the improvements are limited to internal error message formatting.

Changes

File(s) Summary of Changes
athina/steps/llm.py Enhanced error messages in PromptExecution methods to include response type and a content preview snippet.
pyproject.toml Incremented athina package version from 1.7.35 to 1.7.36.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant PromptExecution
    participant LLMService

    User->>PromptExecution: execute / execute_async / execute_stream
    PromptExecution->>LLMService: Send prompt
    LLMService-->>PromptExecution: Return response
    alt Response type/format invalid
        PromptExecution-->>User: Raise error with type and preview of response
    else Response valid
        PromptExecution-->>User: Return processed result
    end
Loading

Possibly related PRs

Suggested reviewers

  • vivek-athina

Poem

A bunny with code on its mind,
Tweaked errors to be more refined.
Now when things go askew,
You'll see type and a preview—
Debugging's a hop, not a grind!
🐇✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Lite

📥 Commits

Reviewing files that changed from the base of the PR and between 6adb2e2 and f47cd1d.

📒 Files selected for processing (1)
  • athina/steps/llm.py (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • athina/steps/llm.py

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🔭 Outside diff range comments (2)
athina/steps/llm.py (2)

358-359: ⚠️ Potential issue

Address the unused variable warning.

The code comment "TODO: Why is api_formatted_messages not used?" indicates awareness of the issue, but it should be fixed to silence the linter warning. Either use the variable or remove it.

-            # TODO: Why is api_formatted_messages not used?
-            api_formatted_messages = [msg.to_api_format() for msg in messages]

Alternatively, if it needs to be kept for future reference:

-            # TODO: Why is api_formatted_messages not used?
-            api_formatted_messages = [msg.to_api_format() for msg in messages]
+            # TODO: Why is this conversion not used? Keeping for reference
+            # api_formatted_messages = [msg.to_api_format() for msg in messages]
🧰 Tools
🪛 Ruff (0.8.2)

359-359: Local variable api_formatted_messages is assigned to but never used

Remove assignment to unused variable api_formatted_messages

(F841)

🪛 GitHub Actions: Flake8, Pyflakes and Compileall Linter

[warning] 4-359: Unused import 'athina.helpers.json.JsonExtractor' and local variable 'api_formatted_messages' is assigned to but never used.


1-5: ⚠️ Potential issue

Remove unused import to fix linter warning.

The static analysis shows that JsonExtractor is imported but never used in this file.

from pydantic import BaseModel
from typing import List, Dict, Any, Optional, Union
-from athina.helpers.json import JsonExtractor
from athina.interfaces.model import Model
from athina.steps.base import Step
🧰 Tools
🪛 Ruff (0.8.2)

4-4: athina.helpers.json.JsonExtractor imported but unused

Remove unused import: athina.helpers.json.JsonExtractor

(F401)

🧹 Nitpick comments (1)
athina/steps/llm.py (1)

512-515: Consider using final_response for type information in streaming context.

While this enhancement is valuable, in the streaming context, you're using llmresponse which contains the current chunk, but using type(final_response) might be more appropriate for reporting the type of the complete response that failed validation.

-                        error += (
-                            f" | Received type: {type(llmresponse).__name__} | "
-                            f"Preview: {repr(llmresponse)[:300]}"
-                        )
+                        error += (
+                            f" | Received type: {type(final_response).__name__} | "
+                            f"Preview: {repr(final_response)[:300]}"
+                        )
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 68511e7 and d40f3b1.

📒 Files selected for processing (1)
  • athina/steps/llm.py (3 hunks)
🧰 Additional context used
🪛 GitHub Actions: Flake8, Pyflakes and Compileall Linter
athina/steps/llm.py

[warning] 4-359: Unused import 'athina.helpers.json.JsonExtractor' and local variable 'api_formatted_messages' is assigned to but never used.

🪛 GitHub Actions: MyPy static type checker
athina/steps/llm.py

[error] 326-465: mypy errors: Incompatible return value types (got 'StepResult', expected 'str' or 'dict'). Missing attribute 'chat_completion_async'. Argument 'status' to '_create_step_result' has incompatible type 'Literal[in_progress]' [return-value, attr-defined, arg-type]

🔇 Additional comments (3)
athina/steps/llm.py (3)

322-325: Good addition of context to error messages.

Adding the received type and a preview of the response will make it much easier to debug type mismatch issues when they occur.


408-411: Good enhancement for error diagnostics.

This change maintains consistency with the error handling in the execute method, making debugging easier for the async version as well.


361-362:

Details

❓ Verification inconclusive

Fix type checking error for async method.

The pipeline failure shows a Missing attribute 'chat_completion_async' error, suggesting that the async method might be calling a non-existent function. Verify that self.llm_service implements this method.


🏁 Script executed:

#!/bin/bash
# Check if AbstractLlmService or its implementations define chat_completion_async
rg -A 2 -B 2 'def chat_completion_async' --type py

Length of output: 52


#!/bin/bash
# Locate all service classes to inspect available methods
rg -A5 -B5 'class \w*LlmService' --type py

# Check for the synchronous chat_completion implementation
rg -A2 -B2 'def chat_completion' --type py

# Re-check for any async chat_completion_async definitions
rg -A2 -B2 'def chat_completion_async' --type py

#!/bin/bash
# Find all LlmService classes (including AbstractLlmService and implementations)
rg -n "class .*LlmService" --type py

# Search for any definition or override of chat_completion (sync or async)
rg -n "chat_completion" --type py

#!/bin/bash
# 1. Locate AbstractLlmService definition and list its methods
rg -n "class AbstractLlmService" --type py
rg -A20 -B1 "class AbstractLlmService" --type py

# 2. Find all concrete LlmService implementations and inspect them
rg -n "class .*LlmService" --type py
rg -A20 -B1 "class .*LlmService" --type py

# 3. Search for any async chat_completion method definitions
rg -n "def chat_completion_async" --type py

Ensure chat_completion_async Exists on All LLM Service Classes

It appears there’s no chat_completion_async method defined on AbstractLlmService or any concrete *LlmService implementations. Please verify and address the discrepancy:

• Confirm whether AbstractLlmService declares async def chat_completion_async(…).
• For each concrete LLM service (e.g. OpenAIService, AzureLlmService), ensure they implement or override chat_completion_async.
• If the intended method is synchronous (chat_completion), update the call site accordingly or add an async alias in your base/service classes.

@codyathina codyathina requested a review from vivek-athina April 24, 2025 15:02
@vivek-athina vivek-athina merged commit b61b7de into main Apr 24, 2025
0 of 2 checks passed
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