chore(types): Type-clean library/ (142 errors) #1389
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.
Description
This PR cleans type-errors reported by Pyright. These were all checked with unit-tests and validated with Pyright after the fixes.
Each section below corresponds to a subdirectory under
nemoguardrails/library
and lists the type fixes that were applied, along with the GitHub username of the original author responsible for the problematic code. The aim is to check with the original authors and companies who own the integrations where possible before merging these changes.activefence/
No type errors reported for this directory.
attention/
Author: @sklingler (Severin Klingler)
Type Error Fixed:
Cannot assign to attribute "corrected_datetime" for class "ActionEvent"
setattr()
to dynamically add thecorrected_datetime
attribute since neitherActionEvent
nor its base classEvent
have this attribute defined.event.corrected_datetime = timestamp + timedelta(seconds=offsets.get(event.name, 0.0))
setattr(event, "corrected_datetime", corrected_time)
autoalign/
Author: @abhijitpal1247 (Abhijit Pal)
Type Errors Fixed:
Lines 176-180: Multiple
"keys" is not a known attribute of "None"
andObject of type "None" is not subscriptable
errorstask_config
before accessing its methods and propertiestask_config.keys()
andtask_config[task]
if task_config is not None:
blockLines 290, 330, 370, 408-409:
"get" is not a known attribute of "None"
errorsLines 303, 343, 385, 419-420: Argument type errors for functions expecting
str
but receivingNone
clavata/
Author: @ilyasnv (Ilias)
Type Error Fixed:
"policy_id" is possibly unbound
policy_id
outside the try block to ensure it's always defined before usepolicy_id
was assigned inside try block but used in exception handlerpolicy_id = config.policies.get(policy)
and added null check before the try blockcleanlab/
Author: @ashishsardana21 (Ashish Sardana)
Type Errors Fixed:
Line 47:
Import "cleanlab_studio" could not be resolved
Lines 53-54:
"get" is not a known attribute of "None"
errorscontent_safety/
Author: @Pouyanpi (Pouyan Rezakhani)
Type Errors Fixed:
Lines 75, 154:
Argument of type "LLMCallInfo" cannot be assigned to parameter "value" of type "None"
LLMCallInfo
instead ofNone
Lines 82, 159:
Argument of type "str" cannot be assigned to parameter "task" of type "Task"
Task
enum values instead of string literalsfactchecking/align_score/
Author: @Pouyanpi (Pouyan)
Type Errors Fixed:
Lines 55-56:
"get" is not a known attribute of "None"
errorsserver.py Lines 20, 23: Missing import errors for
nltk
andalignscore
server.py Line 54:
Argument of type "str | None" cannot be assigned to parameter "a" of type "StrPath"
fiddler/
Author: @copperstick6 (William Han)
Type Errors Fixed:
"get" is not a known attribute of "None"
errorsgcp_moderate_text/
Author: @Pouyanpi (Pouyan)
Type Errors Fixed:
Lines 20, 119:
"language_v2" is unknown import symbol
Line 127:
"get" is not a known attribute of "None"
guardrails_ai/
Author: @Pouyanpi (Pouyan)
Type Errors Fixed:
Line 24:
Import "guardrails" could not be resolved
Lines 113, 117-119, 152, 156-158: Multiple
"get" is not a known attribute of "None"
and attribute access errorshallucination/
Author: @Pouyanpi (Pouyan)
Type Errors Fixed:
Line 56:
Import "langchain_openai" could not be resolved
Lines 62-63:
"get" is not a known attribute of "None"
errorsLines 131, 134: Type assignment and attribute access errors
injection_detection/
Author: @Pouyanpi (Pouyan Rezakhani) and @egalikin (Erick Galinkin)
Type Errors Fixed:
Lines 133, 140, 144, 162:
"attribute" is not a known attribute of "None"
errorsLines 162, 167, 212, 256, 292: Type annotation and return type errors
Lines 196, 204-205: YARA compilation errors
jailbreak_detection/
Author: @egalikin (Erick Galinkin)
Type Errors Fixed:
Lines 55-59: Multiple configuration attribute access errors
Lines 70, 72, 78: Function argument type errors expecting
str
but receivingNone
Lines 97-100: Configuration attribute access errors
Lines 133, 140, 145: Variable binding and type errors
llama_guard/
Author: @PrasoonV (Prasoon Varshney)
Type Errors Fixed:
Lines 67, 112-113:
"get" is not a known attribute of "None"
errorsLines 77, 79-80, 125, 127-128: LLM argument type errors
patronusai/
Author: @varun (Varun Joshi)
Type Errors Fixed:
Lines 86-88, 256-258:
"get" is not a known attribute of "None"
errorsLines 115, 118, 120: LLM argument type errors and variable assignment errors
Line 260:
"output" is not a known attribute of "None"
self_check/facts/
Author: @Pouyanpi (Pouyan Rezakhani)
Type Errors Fixed:
Lines 54-55:
"get" is not a known attribute of "None"
errorsLines 73, 75-76: LLM argument type errors and configuration attribute access
self_check/input_check/
Author: @Pouyanpi (Pouyan Rezakhani)
Type Errors Fixed:
Line 52:
"get" is not a known attribute of "None"
Lines 67, 70, 72: LLM argument type errors and configuration attribute access
self_check/output_check/
Author: @Pouyanpi (Pouyan Rezakhani)
Type Errors Fixed:
Lines 54-55:
"get" is not a known attribute of "None"
errorsLines 72, 75, 77: LLM argument type errors and configuration attribute access
sensitive_data_detection/
Author: @Pouyanpi (Pouyan Rezakhani)
Type Errors Fixed:
Lines 20-23, 43, 52: Multiple import resolution errors for
presidio_*
andspacy
Lines 71, 84, 165, 173: Variable binding errors for imported classes
Lines 131, 171: Function argument type errors
topic_safety/
Author: @makeshn (Makesh)
Type Errors Fixed:
Lines 53-54:
Cannot access attribute "name"/"arguments" for class "dict[Unknown, Unknown]"
Line 90:
Cannot access attribute "strip" for class "List[dict[Unknown, Unknown]]"
Lines 97, 103: Type assignment and variable binding errors
Summary
A total of 145 type errors were fixed across 28 files in the library directory. The most common issues were:
None
objectsThe fixes generally involved adding proper null checks, type validation, and error handling for optional dependencies.
Test Plan
Type-checking
Unit-tests
Local CLI check
Related Issue(s)
Top-level PR to merge into before develop-branch merge: #1367
Checklist