datarobot_genai.drmcpbase.dynamic_tools.schema
schema
SchemaValidationError
PropertyConfig
dataclass
Configuration for top-level input schema property types.
Source code in datarobot_genai/drmcpbase/dynamic_tools/schema.py
SchemaResolver
Helper class to resolve JSON schema references and handle unions.
Source code in datarobot_genai/drmcpbase/dynamic_tools/schema.py
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 | |
__init__
Initialize resolver with definitions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
definitions
|
dict[str, Any] | None
|
Dictionary of reusable schema definitions ($defs) |
None
|
Source code in datarobot_genai/drmcpbase/dynamic_tools/schema.py
resolve_ref
Resolve a JSON Schema $ref reference.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ref_path
|
str
|
The reference path (e.g., '#/$defs/ModelName') |
required |
Returns
The resolved schema definition
Raises
SchemaValidationError: If the reference cannot be resolved
Source code in datarobot_genai/drmcpbase/dynamic_tools/schema.py
resolve_schema
Resolve a schema, following $ref if present.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
schema
|
dict[str, Any]
|
Schema that may contain a $ref |
required |
Returns
Resolved schema
Source code in datarobot_genai/drmcpbase/dynamic_tools/schema.py
resolve_optional_union
Resolve anyOf/oneOf unions for optional fields (Type | None).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
schema
|
dict[str, Any]
|
Schema that may contain anyOf/oneOf |
required |
Returns
Resolved schema for the non-null variant, or original schema
if it's a complex union
Raises
SchemaValidationError: If union is too complex
Source code in datarobot_genai/drmcpbase/dynamic_tools/schema.py
FieldTypeResolver
Resolves Python types for JSON schema fields.
Source code in datarobot_genai/drmcpbase/dynamic_tools/schema.py
195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 | |
__init__
Initialize field type resolver.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_name
|
str
|
Name of the parent model |
required |
allow_nested
|
bool
|
Whether nested objects/arrays are allowed |
required |
resolver
|
SchemaResolver
|
Schema resolver for handling references |
required |
Source code in datarobot_genai/drmcpbase/dynamic_tools/schema.py
resolve
Resolve the Python type for a JSON schema field.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
field_name
|
str
|
Name of the field |
required |
field_spec
|
dict[str, Any]
|
JSON schema specification for the field |
required |
Returns
Python type annotation for the field
Source code in datarobot_genai/drmcpbase/dynamic_tools/schema.py
InputSchemaPropertyHandler
Handles processing of input schema properties with validation.
Source code in datarobot_genai/drmcpbase/dynamic_tools/schema.py
__init__
Initialize property handler.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
PropertyConfig
|
Configuration for this property type |
required |
resolver
|
SchemaResolver
|
Schema resolver for handling references |
required |
Source code in datarobot_genai/drmcpbase/dynamic_tools/schema.py
process_property
process_property(property_name: str, property_schema: dict[str, Any]) -> tuple[type[Any], FieldInfo]
Process a property schema and return its field definition.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
property_name
|
str
|
Name of the property |
required |
property_schema
|
dict[str, Any]
|
Schema definition for the property |
required |
Returns
Tuple of (type, FieldInfo) for the property
Source code in datarobot_genai/drmcpbase/dynamic_tools/schema.py
json_schema_to_python_type
Convert JSON schema type to Python type annotation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
schema_type
|
str | list[str]
|
JSON schema type string or list of type strings |
required |
Returns
Python type annotation corresponding to the schema type
Source code in datarobot_genai/drmcpbase/dynamic_tools/schema.py
create_schema_model
create_schema_model(name: str, schema: dict[str, Any], allow_nested: bool, definitions: dict[str, Any] | None = None) -> type[BaseModel]
Create a Pydantic model from a JSON schema, supporting nested objects.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Name for the generated model |
required |
schema
|
dict[str, Any]
|
JSON schema defining the model structure |
required |
allow_nested
|
bool
|
Whether to allow nested objects and arrays in the schema. If False, raises error on complex types. |
required |
definitions
|
dict[str, Any] | None
|
Dictionary of reusable schema definitions ($defs) |
None
|
Returns
A Pydantic BaseModel class
Source code in datarobot_genai/drmcpbase/dynamic_tools/schema.py
create_input_schema_pydantic_model
create_input_schema_pydantic_model(input_schema: dict[str, Any], model_name: str = 'InputSchema', allow_empty: bool = False) -> type[BaseModel]
Create a properly typed ExternalToolRegistrationConfig with validated sub-schemas.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_schema
|
dict[str, Any]
|
JSON schema for input parameters |
required |
model_name
|
str
|
Name for the generated Pydantic model |
'InputSchema'
|
allow_empty
|
bool
|
Whether to allow empty schema (no properties) |
False
|
Returns
A Pydantic BaseModel class with properly typed fields
Raises
SchemaValidationError: If schema validation fails