Skip to content

Conversation

@smithjilks
Copy link
Contributor

@smithjilks smithjilks commented Jan 15, 2026

Signed-off-by: Jilks Smith smithjilks@gmail.com

What type of PR is this?

This is a bug fix because it routes llm requests from Nemo Guardrails through the proxy.

What does this do?

Routes llm requests from Nemo Guardrails through the proxy.

Which issue(s) does this PR fix/relate to?

Resolves #51

Have you included tests for your changes?

No.

Did you document any new/modified features?

No.

Notes

@smithjilks smithjilks requested a review from SammyOina January 15, 2026 07:51
@smithjilks smithjilks self-assigned this Jan 15, 2026
@smithjilks smithjilks force-pushed the NOISSUE-guardrails-sidecar branch from e3fac57 to dcc852e Compare January 15, 2026 14:06
@smithjilks smithjilks changed the title (DRAFT) NOISSUE - Refactor guardrails to sidecar NOISSUE - Refactor guardrails to sidecar Jan 15, 2026
@smithjilks smithjilks force-pushed the NOISSUE-guardrails-sidecar branch 2 times, most recently from 2a61df1 to 7250492 Compare January 19, 2026 23:58

cleaned = response.strip()

cleaned = re.sub(r'^(bot|I)\s+\w+(\s+\w+)*\s*\n', '', cleaned, flags=re.IGNORECASE)
Copy link
Contributor

Choose a reason for hiding this comment

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

removes any first line that begins with “I …”, which will delete normal assistant answers. Constrain this to explicit prefixes

return cleaned.strip()


@router.post("/messages", tags=["chat"])
Copy link
Contributor

Choose a reason for hiding this comment

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

we should not have this endpoint

Copy link
Contributor

Choose a reason for hiding this comment

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

if it is purely internal you can leave it

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is internal. And it's needed. Perhaps renaming, but the functionality remains the same: to receive chat contents in the Guardrails service.

if !ok {
func guardrailsHandler(transport http.RoundTripper, rter *router.Router) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
if r.Header.Get("X-Guardrails-Request") != "true" {
Copy link
Contributor

Choose a reason for hiding this comment

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

any client can bypass it by simply adding the header. Replace the header check with proper authentication—either apply the same authn.Middleware() used elsewhere or validate a cryptographically signed token.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Best way to handle is this is building a custom LLM wrapper.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Best way to handle is this is building a custom LLM wrapper.

return nil, 0, err
}
defer resp.Body.Close()
req.URL.RawQuery = target.RawQuery
Copy link
Contributor

Choose a reason for hiding this comment

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

Current logic overwrites the incoming query if target.RawQuery is set. Merge them to avoid losing client parameters.

@smithjilks smithjilks force-pushed the NOISSUE-guardrails-sidecar branch from dcd2de0 to 70fbf66 Compare January 26, 2026 12:17
modelAuth = bearerPrefix + modelAuth
}

r.Header.Set(authorizationHeader, modelAuth)
Copy link
Contributor

Choose a reason for hiding this comment

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

remove X -Model-Authorization since it is not used downstream

)

# Extract text from ChatResult
return result.generations[0].text
Copy link
Contributor

Choose a reason for hiding this comment

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

if generations is nil, will panic

Signed-off-by: Jilks Smith <smithjilks@gmail.com>
Signed-off-by: Jilks Smith <smithjilks@gmail.com>
Signed-off-by: Jilks Smith <smithjilks@gmail.com>
Signed-off-by: Jilks Smith <smithjilks@gmail.com>
Signed-off-by: Jilks Smith <smithjilks@gmail.com>
Signed-off-by: Jilks Smith <smithjilks@gmail.com>
Signed-off-by: Jilks Smith <smithjilks@gmail.com>
Signed-off-by: Jilks Smith <smithjilks@gmail.com>
@smithjilks smithjilks force-pushed the NOISSUE-guardrails-sidecar branch from b492ec7 to 85dfc23 Compare January 28, 2026 08:57
@drasko drasko merged commit 7db6985 into ultravioletrs:main Jan 28, 2026
5 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.

Feature: Implement Robust AI Guardrails and Content Moderation

3 participants