Skip to content

Conversation

@JashG
Copy link
Contributor

@JashG JashG commented Oct 20, 2025

Description

This PR logs the model name and base URL before an LLM is invoked.

Some context: From the NeMo Guardrails microservice, we've run into different errors that can be root caused to the incorrect base URL being used for a model. This can be difficult to root cause, since neither the URL nor model gets logged at any point in the call chain.

Related Issue(s)

Checklist

  • I've read the CONTRIBUTING guidelines.
  • I've updated the documentation if applicable.
  • I've added tests if applicable.
  • @mentions of the person or team responsible for reviewing proposed changes.

@codecov-commenter
Copy link

Codecov Report

❌ Patch coverage is 80.95238% with 4 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
nemoguardrails/actions/llm/utils.py 80.95% 4 Missing ⚠️

📢 Thoughts on this report? Let us know!

@JashG JashG marked this pull request as ready for review October 20, 2025 17:11
@JashG
Copy link
Contributor Author

JashG commented Oct 20, 2025

Looks like the failing test_stats_logging_interval_timing test is flakey with a fix in #1463

@Pouyanpi
Copy link
Collaborator

Thanks for the PR @JashG ! I agree this feature looks really useful for debugging!

I have one suggestion: it might be better to move this logging logic to the LoggingCallbackHandler in nemoguardrails/logging/callbacks.py instead of utils.py.
here’s why:

  1. all LLM related logs already go through the callbacks (on_llm_start, on_chat_model_start, etc.), so it keeps things consistent and easier to maintain.
  2. the current approach logs twice (once for string prompts and once for message lists), while callbacks handle each LLM call once.
  3. more context available, the serialized parameter in callbacks includes metadata like model configuration and base URLs.

Implementation details:
You can get the base URL directly from the serialized parameter:

  • for ChatOpenAI: serialized['kwargs']['openai_api_base']
  • for ChatNVIDIA: extract it from serialized['repr']
    and this is provider dependent.

that way, the log would appear right before the existing “Invocation Params” entry in on_llm_start() and on_chat_model_start(), keeping all the LLM call logs together.

what do you think?

@Pouyanpi Pouyanpi self-requested a review October 21, 2025 09:17
@Pouyanpi
Copy link
Collaborator

Looks like the failing test_stats_logging_interval_timing test is flakey with a fix in #1463

Yes, we merged the fix to develop. You might want to do a rebase 👍🏻

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.

3 participants