TypeError: expected string or bytes-like object, got 'NoneType'

Hello!
I am trying to enable my agent to use the “integration with ProxyCURL” tool.
The agent accesses the service, I can see how it finds the person’s mail or not - it doesn’t matter, at the moment when the agent’s chain of actions completes and it should have saved the response to a file and finished its work - the process aborts with the error below.


🖇 AgentOps: Session Stats - Duration: 31.3s | Cost: $0.078204 | LLMs: 12 | Tools: 0 | Actions: 0 | Errors: 0
🖇 AgentOps: Session Replay: https://app.agentops.ai/drilldown?session_id=03c9ccb8-8c72-4cf1-9ea3-327ec69d63b0
Traceback (most recent call last):
  File "/Users/rzymer/Documents/VSCode/Outreach agent/fresh_env/lib/python3.11/site-packages/crewai/agent.py", line 236, in execute_task
    result = self.agent_executor.invoke(
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/rzymer/Documents/VSCode/Outreach agent/fresh_env/lib/python3.11/site-packages/crewai/agents/crew_agent_executor.py", line 93, in invoke
    formatted_answer = self._invoke_loop()
                       ^^^^^^^^^^^^^^^^^^^
  File "/Users/rzymer/Documents/VSCode/Outreach agent/fresh_env/lib/python3.11/site-packages/crewai/agents/crew_agent_executor.py", line 175, in _invoke_loop
    raise e
  File "/Users/rzymer/Documents/VSCode/Outreach agent/fresh_env/lib/python3.11/site-packages/crewai/agents/crew_agent_executor.py", line 131, in _invoke_loop
    formatted_answer = self._format_answer(answer)
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/rzymer/Documents/VSCode/Outreach agent/fresh_env/lib/python3.11/site-packages/crewai/agents/crew_agent_executor.py", line 376, in _format_answer
    return CrewAgentParser(agent=self.agent).parse(answer)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/rzymer/Documents/VSCode/Outreach agent/fresh_env/lib/python3.11/site-packages/crewai/agents/parser.py", line 73, in parse
    thought = self._extract_thought(text)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/rzymer/Documents/VSCode/Outreach agent/fresh_env/lib/python3.11/site-packages/crewai/agents/parser.py", line 120, in _extract_thought
    thought_match = re.search(regex, text, re.DOTALL)
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/anaconda3/envs/outr_env/lib/python3.11/re/__init__.py", line 176, in search
    return _compile(pattern, flags).search(string)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: expected string or bytes-like object, got 'NoneType'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/rzymer/Documents/VSCode/Outreach agent/fresh_env/lib/python3.11/site-packages/crewai/agent.py", line 236, in execute_task
    result = self.agent_executor.invoke(
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/rzymer/Documents/VSCode/Outreach agent/fresh_env/lib/python3.11/site-packages/crewai/agents/crew_agent_executor.py", line 93, in invoke
    formatted_answer = self._invoke_loop()
                       ^^^^^^^^^^^^^^^^^^^
  File "/Users/rzymer/Documents/VSCode/Outreach agent/fresh_env/lib/python3.11/site-packages/crewai/agents/crew_agent_executor.py", line 175, in _invoke_loop
    raise e
  File "/Users/rzymer/Documents/VSCode/Outreach agent/fresh_env/lib/python3.11/site-packages/crewai/agents/crew_agent_executor.py", line 131, in _invoke_loop
    formatted_answer = self._format_answer(answer)
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/rzymer/Documents/VSCode/Outreach agent/fresh_env/lib/python3.11/site-packages/crewai/agents/crew_agent_executor.py", line 376, in _format_answer
    return CrewAgentParser(agent=self.agent).parse(answer)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/rzymer/Documents/VSCode/Outreach agent/fresh_env/lib/python3.11/site-packages/crewai/agents/parser.py", line 73, in parse
    thought = self._extract_thought(text)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/rzymer/Documents/VSCode/Outreach agent/fresh_env/lib/python3.11/site-packages/crewai/agents/parser.py", line 120, in _extract_thought
    thought_match = re.search(regex, text, re.DOTALL)
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/anaconda3/envs/outr_env/lib/python3.11/re/__init__.py", line 176, in search
    return _compile(pattern, flags).search(string)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: expected string or bytes-like object, got 'NoneType'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/rzymer/Documents/VSCode/Outreach agent/main.py", line 355, in <module>
    result = crew.kickoff(inputs={
             ^^^^^^^^^^^^^^^^^^^^^
  File "/Users/rzymer/Documents/VSCode/Outreach agent/fresh_env/lib/python3.11/site-packages/crewai/crew.py", line 494, in kickoff
    result = self._run_sequential_process()
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/rzymer/Documents/VSCode/Outreach agent/fresh_env/lib/python3.11/site-packages/crewai/crew.py", line 598, in _run_sequential_process
    return self._execute_tasks(self.tasks)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/rzymer/Documents/VSCode/Outreach agent/fresh_env/lib/python3.11/site-packages/crewai/crew.py", line 696, in _execute_tasks
    task_output = task.execute_sync(
                  ^^^^^^^^^^^^^^^^^^
  File "/Users/rzymer/Documents/VSCode/Outreach agent/fresh_env/lib/python3.11/site-packages/crewai/task.py", line 191, in execute_sync
    return self._execute_core(agent, context, tools)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/rzymer/Documents/VSCode/Outreach agent/fresh_env/lib/python3.11/site-packages/crewai/task.py", line 247, in _execute_core
    result = agent.execute_task(
             ^^^^^^^^^^^^^^^^^^^
  File "/Users/rzymer/Documents/VSCode/Outreach agent/fresh_env/lib/python3.11/site-packages/crewai/agent.py", line 248, in execute_task
    result = self.execute_task(task, context, tools)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/rzymer/Documents/VSCode/Outreach agent/fresh_env/lib/python3.11/site-packages/crewai/agent.py", line 248, in execute_task
    result = self.execute_task(task, context, tools)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/rzymer/Documents/VSCode/Outreach agent/fresh_env/lib/python3.11/site-packages/crewai/agent.py", line 247, in execute_task
    raise e
  File "/Users/rzymer/Documents/VSCode/Outreach agent/fresh_env/lib/python3.11/site-packages/crewai/agent.py", line 236, in execute_task
    result = self.agent_executor.invoke(
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/rzymer/Documents/VSCode/Outreach agent/fresh_env/lib/python3.11/site-packages/crewai/agents/crew_agent_executor.py", line 93, in invoke
    formatted_answer = self._invoke_loop()
                       ^^^^^^^^^^^^^^^^^^^
  File "/Users/rzymer/Documents/VSCode/Outreach agent/fresh_env/lib/python3.11/site-packages/crewai/agents/crew_agent_executor.py", line 175, in _invoke_loop
    raise e
  File "/Users/rzymer/Documents/VSCode/Outreach agent/fresh_env/lib/python3.11/site-packages/crewai/agents/crew_agent_executor.py", line 131, in _invoke_loop
    formatted_answer = self._format_answer(answer)
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/rzymer/Documents/VSCode/Outreach agent/fresh_env/lib/python3.11/site-packages/crewai/agents/crew_agent_executor.py", line 376, in _format_answer
    return CrewAgentParser(agent=self.agent).parse(answer)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/rzymer/Documents/VSCode/Outreach agent/fresh_env/lib/python3.11/site-packages/crewai/agents/parser.py", line 73, in parse
    thought = self._extract_thought(text)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/rzymer/Documents/VSCode/Outreach agent/fresh_env/lib/python3.11/site-packages/crewai/agents/parser.py", line 120, in _extract_thought
    thought_match = re.search(regex, text, re.DOTALL)
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/anaconda3/envs/outr_env/lib/python3.11/re/__init__.py", line 176, in search
    return _compile(pattern, flags).search(string)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: expected string or bytes-like object, got 'NoneType'
(fresh_env) MacBook-Pro-4:Outreach agent rzymer$ 

Tool code:

@tool("Fetch email from LinkedIn profile")
def fetch_email_from_linkedin(linkedin_url: str) -> str:
    """Fetches all available emails associated with a LinkedIn profile."""
    if not linkedin_url or not isinstance(linkedin_url, str):
        return "ProxyCurl: Invalid LinkedIn URL provided"
        
    try:
        # Clean up the LinkedIn URL
        linkedin_url = linkedin_url.strip()
        if not linkedin_url.startswith(('http://', 'https://')):
            linkedin_url = 'https://' + linkedin_url
            
        api_endpoint = 'https://nubela.co/proxycurl/api/v2/linkedin'
        headers = {'Authorization': f'Bearer {proxycurl_api_key}'}
        
        params = {
            'url': linkedin_url,
            'personal_email': 'include',
            'personal_contact_number': 'include',
            'email': 'include'
        }
        
        response = requests.get(
            api_endpoint,
            params=params,
            headers=headers,
            timeout=10
        )
        
        if response.status_code != 200:
            return f"ProxyCurl: API error {response.status_code}"
            
        data = response.json()
        emails = []
        
        # Extract emails from various fields
        if data.get('personal_email'):
            emails.append(data['personal_email'])
        if data.get('work_email'):
            emails.append(data['work_email'])
        if data.get('email'):
            emails.append(data['email'])
            
        # Remove duplicates and empty values
        emails = list(set(filter(None, emails)))
        
        if not emails:
            return "ProxyCurl: No emails found"
            
        return f"ProxyCurl: {', '.join(emails)}"
        
    except requests.exceptions.Timeout:
        return "ProxyCurl: Request timed out"
    except requests.exceptions.RequestException as e:
        return f"ProxyCurl: Network error - {str(e)}"
    except Exception as e:
        return f"ProxyCurl: Error - {str(e)}"

Please can anyone help?