MCPcopy
hub / github.com/langchain-ai/langchain / _parse_input

Method _parse_input

libs/core/langchain_core/tools.py:291–310  ·  view source on GitHub ↗

Convert tool input to pydantic model.

(
        self,
        tool_input: Union[str, Dict],
    )

Source from the content-addressed store, hash-verified

289 # --- Tool ---
290
291 def _parse_input(
292 self,
293 tool_input: Union[str, Dict],
294 ) -> Union[str, Dict[str, Any]]:
295 """Convert tool input to pydantic model."""
296 input_args = self.args_schema
297 if isinstance(tool_input, str):
298 if input_args is not None:
299 key_ = next(iter(input_args.__fields__.keys()))
300 input_args.validate({key_: tool_input})
301 return tool_input
302 else:
303 if input_args is not None:
304 result = input_args.parse_obj(tool_input)
305 return {
306 k: getattr(result, k)
307 for k, v in result.dict().items()
308 if k in tool_input
309 }
310 return tool_input
311
312 @root_validator(pre=True)
313 def raise_deprecation(cls, values: Dict) -> Dict:

Callers 2

runMethod · 0.95
arunMethod · 0.95

Calls 4

keysMethod · 0.80
validateMethod · 0.45
parse_objMethod · 0.45
dictMethod · 0.45

Tested by

no test coverage detected