Skip to content

generator: NeMoGuardrails server support#1675

Open
jmartin-tech wants to merge 5 commits intoNVIDIA:mainfrom
jmartin-tech:feature/nemoguardrails-server
Open

generator: NeMoGuardrails server support#1675
jmartin-tech wants to merge 5 commits intoNVIDIA:mainfrom
jmartin-tech:feature/nemoguardrails-server

Conversation

@jmartin-tech
Copy link
Copy Markdown
Collaborator

@jmartin-tech jmartin-tech commented Apr 8, 2026

Add support for new OpenAICompatible service exposed via NVIDIA-NeMo/Guardrails

Verification

List the steps needed to make sure this thing works

  • Supporting configuration file
plugins:
  target_type: guardrails.NeMoGuardrailsServer
  target_name: meta/llama-3.3-70b-instruct
  generators:
    guardrails:
      NeMoGuardrailsServer:
        uri: http://localhost:8005/v1/
        config_ids:
          - abc
  • start a NeMoGuardrails service example used is abc bot with a revised backing model and default config_id:
NVIDIA_API_KEY="my super secret" MAIN_MODEL_ENGINE='nim' nemoguardrails server --config abc/ --port 8000 --default-config-id abc
  • garak -t guardrails.NeMoGuardrailsServer -n meta/llama-3.3-70b-instruct -p lmrc

  • Verify the target guardrails configuration responds

  • start a NeMoGuardrails service example used is abc bot with a revised backing model without a default config_id:

NVIDIA_API_KEY="my super secret" MAIN_MODEL_ENGINE='nim' nemoguardrails server --config abc/ --port 8005
  • garak --config config.guardrails.yaml -p lmrc
  • Verify the target guardrails abc configuration is activated and responds

Signed-off-by: Jeffrey Martin <jemartin@nvidia.com>
Signed-off-by: Jeffrey Martin <jemartin@nvidia.com>
Signed-off-by: Jeffrey Martin <jemartin@nvidia.com>
@jmartin-tech jmartin-tech force-pushed the feature/nemoguardrails-server branch from 6f27809 to 20fb006 Compare April 8, 2026 16:02
Copy link
Copy Markdown
Collaborator

@leondz leondz left a comment

Choose a reason for hiding this comment

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

couple of requests for clarification

self.extra_body = {"guardrails": guardrails}


DEFAULT_CLASS = "NeMoGuardrails"
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Is this still a sensible default?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I would be in favor of shifting if there is consensus. That would elevate this to a breaking change for this addition as configurations that did not specify -t guardrails.NeMoGuardrails would change behavior.

Comment thread garak/generators/guardrails.py
}

def __init__(self, name="", config_root=_config):
self.api_key = "not-used" # suppress any api_key from being sent as the server does not utilize one
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

is it worth setting ENV_VAR/key_env_var to None, or deleting ENV_VAR, to reduce potential confusion from this attr being inherited?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Interesting point, currently NeMo Guardrails server does not offer any built in authentication, leading to the suppression added here is matched to the public docs from the sdk. I agree there is some confusion created by keeping the ENV_VAR on the class. I will test other patterns for this suppression.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

ENV_VAR is inherited so I added support for it being None as a suppression of the requirement in Configurable.

A place holder value still needs to be set here to ensure the openai client library does not raise when no key is supplied or found in their standard variable locations. Should we adjust this to apply the place holder after the call to super() to allow a user to provide api_key or key_env_var explicitly in the config file for this generator? This might future proof this better if NeMo Guardrails were to ever add support for injecting an authentication layer on the the hosting server.

Comment thread garak/generators/guardrails.py
Comment on lines +76 to +79
if hasattr(self, "extra_body") and self.extra_body and self.config_ids:
self.extra_body["guardrails"] = guardrails
else:
self.extra_body = {"guardrails": guardrails}
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

this is mysterious to me. i accept it, and welcome the mystery.

-- is something being worked around here? maybe a brief explanation in the docstring / a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Official docs this was based on here. Will work out how to document this better on the class.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Please validate update in d531028 meets the ask here.

Signed-off-by: Jeffrey Martin <jemartin@nvidia.com>
Signed-off-by: Jeffrey Martin <jemartin@nvidia.com>
Comment thread garak/generators/guardrails.py
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