Skip to content

Guardrails request config validation #371

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 20 commits into from
Apr 17, 2025

Conversation

mdevino
Copy link
Collaborator

@mdevino mdevino commented Apr 16, 2025

Closes #352, and also adds appropriate integration tests.

@mdevino mdevino force-pushed the guardrails_validation_3 branch 2 times, most recently from 3f34002 to b417ca2 Compare April 16, 2025 15:36
Copy link
Collaborator

@declark1 declark1 left a comment

Choose a reason for hiding this comment

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

Thanks @mdevino. I left some nit comments inline but otherwise looks good.

src/utils.rs Outdated
@@ -15,3 +25,43 @@ impl AsUriExt for Url {
Uri::try_from(self.to_string()).unwrap()
}
}

/// Validates guardrails on request.
pub fn validate_guardrails(
Copy link
Collaborator

Choose a reason for hiding this comment

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

Actually, let's just name this validate_detectors since it aligns better with what it does. Can you move it to orchestrator/common/utils.rs?

src/utils.rs Outdated
pub fn validate_guardrails(
request_detectors: &HashMap<String, DetectorParams>,
orchestrator_detectors: &HashMap<String, DetectorConfig>,
allowed_detector_types: Vec<DetectorType>,
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: allowed_detector_types should be a slice instead of a Vec

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thanks. I knew Vec seemed unnecessarly, but couldn't figure out a better way of doing it.

src/utils.rs Outdated
) -> Result<(), Error> {
let whole_doc_chunker_id = DEFAULT_CHUNKER_ID;
let detector_ids = request_detectors.keys();
for detector_id in detector_ids {
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: just iterate over request_detectors.keys() directly instead of assigning to a variable. I would also rename request_detectors to simply detectors.

Copy link
Collaborator

@declark1 declark1 left a comment

Choose a reason for hiding this comment

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

One additional nit that I forgot to comment earlier, otherwise looks good

The if !detectors.is_empty() conditionals aren't needed; if empty, validate_detectors() just returns Ok(())

@mdevino mdevino force-pushed the guardrails_validation_3 branch from 572bdfe to 13dbb4b Compare April 17, 2025 10:14
@mdevino
Copy link
Collaborator Author

mdevino commented Apr 17, 2025

One additional nit that I forgot to comment earlier, otherwise looks good

The if !detectors.is_empty() conditionals aren't needed; if empty, validate_detectors() just returns Ok(())

Nice catch! Fixed.

@declark1 declark1 self-requested a review April 17, 2025 13:46
Copy link
Collaborator

@declark1 declark1 left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

@declark1
Copy link
Collaborator

Hmm, does this need to be rebased?

@mdevino
Copy link
Collaborator Author

mdevino commented Apr 17, 2025

Hmm, does this need to be rebased?

It doesn't seem so:

image

I started working on this when you were halfway through #355, so I had to rebase at some point and resolve conflicts. That's when the extra commits showed up.

mdevino and others added 16 commits April 17, 2025 13:46
Signed-off-by: Mateus Devino <[email protected]>
Co-authored-by: Dan Clark <[email protected]>
Signed-off-by: Mateus Devino <[email protected]>
Co-authored-by: Dan Clark <[email protected]>
Signed-off-by: Mateus Devino <[email protected]>
Co-authored-by: Dan Clark <[email protected]>
Signed-off-by: Mateus Devino <[email protected]>
mdevino and others added 4 commits April 17, 2025 13:46
Co-authored-by: Dan Clark <[email protected]>
Signed-off-by: Mateus Devino <[email protected]>
Co-authored-by: Dan Clark <[email protected]>
Signed-off-by: Mateus Devino <[email protected]>
Signed-off-by: Mateus Devino <[email protected]>
Signed-off-by: Mateus Devino <[email protected]>
@mdevino mdevino force-pushed the guardrails_validation_3 branch from 13dbb4b to 863d033 Compare April 17, 2025 16:49
@declark1 declark1 merged commit bd79b42 into foundation-model-stack:main Apr 17, 2025
2 checks passed
Comment on lines +77 to +97
// input detectors validation
if let Err(error) = validate_detectors(
&input_detectors,
&ctx.config.detectors,
&[DetectorType::TextContents],
false,
) {
let _ = response_tx.send(Err(error)).await;
return;
}

// output detectors validation
if let Err(error) = validate_detectors(
&output_detectors,
&ctx.config.detectors,
&[DetectorType::TextContents],
false,
) {
let _ = response_tx.send(Err(error)).await;
return;
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Since a user issue led to triggering of an error here for the current version of the orchestrator - why are the whole doc chunkers deliberately disallowed here, especially for both input and output streaming? This would disallow a case of say using Granite Guardian as a content detector.

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.

Model type and endpoint mismatch causes 500
3 participants