pydantic_core._pydantic_core.ValidationError: 1 validation error for Crew

task1 = Task(
description=f"““Analyze the fitness requirements for a {age}-year-old {gender}.
Provide recommendations for exercise routines and fitness strategies.””",
agent=fitness_expert,
expected_output=("A comprehensive recomendation to fitness strategies "),
llm=llm
)

    task2 = Task(
        description=f"""Assess nutritional requirements for a {age}-year-old {gender}. 
                    Provide dietary recommendations based on specific nutritional needs.
                    Do not prescribe a medicine""",
        agent=nutritionist,
        expected_output=("A comprehensive recommendation to nutritional needs "),
        llm=llm
    )

    task3 = Task(
        description=f"""Evaluate overall health considerations for a {age}-year-old {gender}. 
                    Provide recommendations for a healthy lifestyle.""",
        agent=doctor,
        expected_output=("A comprehensive recommendation for a healthy lifestyle "),
        llm=llm
    )
    
    health_crew = Crew(
        agents=[fitness_expert, nutritionist, doctor],
        tasks=[task1, task2, task3],
        verbose=2,
        process=Process.sequential,
    )

# Create and Run the Crew
crew_result = health_crew.kickoff()

# Write "No disease" if the user does not have a disease
if disease.lower() != "yes":
    crew_result += f"\n disease: {disease}"

return crew_result

Error :pydantic_core._pydantic_core.ValidationError: 1 validation error for Crew
verbose
Input should be a valid boolean, unable to interpret input [type=bool_parsing, input_value=2, input_type=int]
For further information visit Redirecting...

I am facing above error while running this crew through Gradio. Could you anyone advice how to resolve this error ?

Thanks

Hey Shailaja, first off, welcome to our community!

So, that error you’re hitting is telling you that Crew.verbose needs to be a boolean value – either True or False. It looks like you might have passed an integer instead. It should be set up like this:

health_crew = Crew(
    agents=[fitness_expert, nutritionist, doctor],
    tasks=[task1, task2, task3],
    verbose=True,  # 👈 Here
    process=Process.sequential,
)

And then, a bit further down, there’s another thing: the Crew.kickoff() method returns a CrewOutput object. You can’t just use += to tack a string directly onto that object. What you want to do is append to its raw attribute, which is a string. Something like this:

if disease.lower() != "yes":
    crew_result.raw += f"\n disease: {disease}"  # 👈 Here

Hi Max,
Thanks for your reply. I have fixed all the bugs and now my code is running without error.
I am running the llama3 model to get the crew response. Unfortunately I am not getting output in Gradio UI. My crew is stuck in thinking state, could you please review my code & advice how can I fix the issue.

’ ’ ’
from crewai import Agent, Task, Crew, Process
from langchain.llms import Ollama
from langchain_community.tools import DuckDuckGoSearchRun
from langchain.agents import Tool
import gradio as gr

llm = Ollama(model=“llama3”)

from crewai.tools import BaseTool
from langchain_community.tools import DuckDuckGoSearchRun

class MyCustomDuckDuckGoTool(BaseTool):
name: str = “DuckDuckGo Search Tool”
description: str = “Search the web for a given query.”

def _run(self, query: str) -> str:
    duckduckgo_tool = DuckDuckGoSearchRun()
    
    response = duckduckgo_tool.invoke(query)

    return response

def create_crewai_setup(age, gender, disease):
# Define Agents
fitness_expert = Agent(
role=“Fitness Expert”,
goal=f"““Analyze the fitness requirements for a {age}-year-old {gender} with {disease} and
suggest exercise routines and fitness strategies””“,
backstory=f”““Expert at understanding fitness needs, age-specific requirements,
and gender-specific considerations. Skilled in developing
customized exercise routines and fitness strategies.””",
verbose=True,
llm=llm,
allow_delegation=True,
tools=[MyCustomDuckDuckGoTool()],
)

nutritionist = Agent(
    role="Nutritionist",
    goal=f"""Assess nutritional requirements for a {age}-year-old {gender} with {disease} and 
             provide dietary recommendations""",
    backstory=f"""Knowledgeable in nutrition for different age groups and genders, 
                  especially for individuals of {age} years old. Provides tailored 
                  dietary advice based on specific nutritional needs.""",
    verbose=True,
    llm=llm,
    allow_delegation=True,
)

doctor = Agent(
    role="Doctor",
    goal=f"""Evaluate the overall health considerations for a {age}-year-old {gender} with {disease} and 
             provide recommendations for a healthy lifestyle.Pass it on to the
              disease_expert if you are not an expert of {disease} """,
    backstory=f"""Medical professional experienced in assessing overall health and 
                  well-being. Offers recommendations for a healthy lifestyle 
                  considering age, gender, and disease factors.""",
    verbose=True,
    llm=llm,
    allow_delegation=True,
)

# Check if the person has a disease
if disease.lower() == "yes":
    disease_expert = Agent(
        role="Disease Expert",
        goal=f"""Provide recommendations for managing {disease}""",
        backstory=f"""Specialized in dealing with individuals having {disease}. 
                      Offers tailored advice for managing the specific health condition.
                      Do not prescribe medicines but only give advice.""",
        verbose=True,
        llm=llm,
        allow_delegation=True,
    )
    disease_task = Task(
        description=f"""Provide recommendations for managing {disease}""",
        agent=disease_expert,
        expected_output=("A comprehensive reccomendation to manage disease"),
        llm=llm
    )
    health_crew = Crew(
        agents=[fitness_expert, nutritionist, doctor, disease_expert],
        tasks=[task1, task2, task3, disease_task],
        verbose=True,
        process=Process.sequential,
    )
else:
    # Define Tasks without Disease Expert
    task1 = Task(
        description=f"""Analyze the fitness requirements for a {age}-year-old {gender}. 
                        Provide recommendations for exercise routines and fitness strategies.""",
        agent=fitness_expert,
        expected_output=("A comprehensive recomendation to fitness strategies "),
        llm=llm
    )

    task2 = Task(
        description=f"""Assess nutritional requirements for a {age}-year-old {gender}. 
                    Provide dietary recommendations based on specific nutritional needs.
                    Do not prescribe a medicine""",
        agent=nutritionist,
        expected_output=("A comprehensive recommendation to nutritional needs "),
        llm=llm
    )

    task3 = Task(
        description=f"""Evaluate overall health considerations for a {age}-year-old {gender}. 
                    Provide recommendations for a healthy lifestyle.""",
        agent=doctor,
        expected_output=("A comprehensive recommendation for a healthy lifestyle "),
        llm=llm
    )
    
    health_crew = Crew(
        agents=[fitness_expert, nutritionist, doctor],
        tasks=[task1, task2, task3],
        verbose=True,
        process=Process.sequential,
    )

# Create and Run the Crew
crew_result = health_crew.kickoff()

# Write "No disease" if the user does not have a disease
if disease.lower() != "yes":
    crew_result.raw += f"\n disease: {disease}"

return crew_result

Gradio interface

def run_crewai_app(age, gender, disease):
crew_result = create_crewai_setup(age, gender, disease)
return crew_result

iface = gr.Interface(
fn=run_crewai_app,
inputs=[“text”, “text”, “text”],
outputs=“text”,
title=“CrewAI Health,Nutrion and Fitness Analysis”,
description=“Enter age, gender, and disease (or ‘no’ if there is no disease) to analyze fitness, nutrition, and health strategies.”
)

iface.launch()

’ ’ ’

@shailaja_natarajan, CrewAI definitely supports Ollama models. The docs have a pretty good section on setting up different LLM providers; you can check it out here.

Here’s how you’d typically set it up:

from crewai import LLM

llm = LLM(
    model="ollama/llama3",
    base_url="http://localhost:11434"
)

Hi Max,
I have tried with crewai with Ollama model based on your code snippet. Still I am facing same issue, my crew is stuck in thinking state there is no response for my query. My local Ollama model is running in local host: 11434.

It would be great if you could share any sample end-end example with local Ollama model with CrewAI or advice me where my code went wrong. Thanks

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.