fix: allow Constraints.set_monitoring to disable monitoring for non-string features (v2) - #6325
Merged
mohamedzeidan2021 merged 1 commit intoSep 28, 2026
Conversation
…tring features Per the constraints.json schema, monitoring_config_overrides is a feature-level key (a sibling of name, inferred_type, and the type-specific num_constraints/string_constraints blocks). set_monitoring previously read and wrote it inside feature["string_constraints"], which raised KeyError: 'string_constraints' for any non-string feature and, even for string features, nested the override one level too deep. Read/write the override directly on the feature dict so it works for any feature type and matches the documented schema. Adds tests/unit/sagemaker/monitor/test_monitoring_files.py. Fixes aws#2745
jam-jee
approved these changes
Sep 28, 2026
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue
Fixes #2745 (v2 backport — companion to #6312 which fixes the same bug in v3/
sagemaker-core).sagemaker.model_monitor.Constraints.set_monitoring(enable_monitoring, feature_name=...)only worked for string-type features. For a non-string feature (e.g. binary/Integral likeChurn) it raisedKeyError: 'string_constraints', and even for string features it nested the override one level too deep — insidestring_constraintsrather than at the feature level, contrary to the Model Monitorconstraints.jsonschema.Fix
Per the constraints.json schema,
monitoring_config_overridesis a feature-level key (a sibling ofname,inferred_type, and the type-specificnum_constraints/string_constraintsblocks). The method now reads/writesmonitoring_config_overridesdirectly on the feature dict, so it works for any feature type and places the override where the schema (and the docs) say it belongs. The top-level (feature_name=None) path is unchanged.Before:
After:
Testing
Added
tests/unit/sagemaker/monitor/test_monitoring_files.py(7 tests): non-string feature (the reported case), string feature, enable/disable mapping, preservation of existing overrides, and the top-level no-feature_namepath. Verified they fail against the unpatched source and pass against the fix.blackandflake8clean.Backwards compatibility
No public signature/return/exception change. No other readers of
monitoring_config_overrides/string_constraintsand no other callers ofset_monitoringexist in the codebase. Output for string features moves the override from insidestring_constraintsto the feature level — this corrects the reported bug and matches the documented schema.