Skip to main content

Python Function

Langflow allows you to create a customized tool using the PythonFunction connected to a Tool component. In this example, Regex is used in Python to validate a pattern.


_10
import re
_10
_10
def is_brazilian_zipcode(zipcode: str) -> bool:
_10
pattern = r"\d{5}-?\d{3}"
_10
_10
# Check if the zip code matches the pattern
_10
if re.match(pattern, zipcode):
_10
return True
_10
_10
return False

tip

When a tool is called, it is often desirable to have its output returned directly to the user. You can do this by setting the return_direct flag for a tool to be True.

The AgentInitializer component is a quick way to construct an agent from the model and tools.

info

The PythonFunction is a custom component that uses the LangChain 🦜🔗 tool decorator. Learn more about it here.

⛓️ Langflow Example

Docusaurus themed imageDocusaurus themed image

Download Flow

LangChain Components 🦜🔗

Hi, how can I help you?