MCPcopy Index your code
hub / github.com/TaskingAI/TaskingAI / validate_input

Method validate_input

plugin/app/models/plugin.py:85–129  ·  view source on GitHub ↗
(self, input_params: Dict[str, Any])

Source from the content-addressed store, hash-verified

83 }
84
85 def validate_input(self, input_params: Dict[str, Any]):
86 # Iterate over the input_schema to validate each parameter
87 for key, schema in self.input_schema.items():
88 # Check if the parameter is required but missing
89 if schema.required and key not in input_params:
90 raise ValueError(f"'{key}' is required but not provided.")
91
92 # If the parameter is present, perform type validation
93 if key in input_params:
94 value = input_params[key]
95
96 if value is None:
97 continue
98 # Validate based on the parameter's declared type
99 if schema.type == ParameterType.STRING:
100 if not isinstance(value, str):
101 raise ValueError(f"Expected '{key}' to be a string, got {type(value).__name__}.")
102 elif schema.type == ParameterType.INTEGER:
103 if not isinstance(value, int):
104 raise ValueError(f"Expected '{key}' to be an integer, got {type(value).__name__}.")
105 elif schema.type == ParameterType.NUMBER:
106 if not isinstance(value, (int, float)):
107 raise ValueError(f"Expected '{key}' to be a number, got {type(value).__name__}.")
108 elif schema.type == ParameterType.BOOLEAN:
109 if not isinstance(value, bool):
110 raise ValueError(f"Expected '{key}' to be a boolean, got {type(value).__name__}.")
111 elif schema.type == ParameterType.IMAGE_URL:
112 if not isinstance(value, str) or not value.startswith("http"):
113 raise ValueError(f"Expected '{key}' to be a valid image URL, got {type(value).__name__}.")
114 elif schema.type == ParameterType.FILE_URL:
115 if not isinstance(value, str) or not value.startswith("http"):
116 raise ValueError(f"Expected '{key}' to be a valid file URL, got {type(value).__name__}.")
117 elif schema.type == ParameterType.STRING_ARRAY:
118 if not isinstance(value, list) or not all(isinstance(item, str) for item in value):
119 raise ValueError(f"Expected '{key}' to be a list of strings.")
120 elif schema.type == ParameterType.INTEGER_ARRAY:
121 if not isinstance(value, list) or not all(isinstance(item, int) for item in value):
122 raise ValueError(f"Expected '{key}' to be a list of integers.")
123 elif schema.type == ParameterType.NUMBER_ARRAY:
124 if not isinstance(value, list) or not all(isinstance(item, (int, float)) for item in value):
125 raise ValueError(f"Expected '{key}' to be a list of numbers.")
126 elif schema.type == ParameterType.BOOLEAN_ARRAY:
127 if not isinstance(value, list) or not all(isinstance(item, bool) for item in value):
128 raise ValueError(f"Expected '{key}' to be a list of booleans.")
129 # Additional type checks can be added here for other types if necessary

Callers 1

validate_afterMethod · 0.45

Calls

no outgoing calls

Tested by

no test coverage detected