[Python] Google ADK Building Agent - Pydantic Validation Error

Discussão em 'Python' iniciado por Stack, Junho 13, 2025.

  1. Stack

    Stack Membro Participativo

    I am trying to build an agent in Google adk by passing in some JSON formatted input to one agent as input_schema but for some reason the error keeps popping up.

    QAAgentPrompt = "Checks the information for accuracy, completeness, and consistency."
    ComplianceAgentPrompt = "Reviews the information for adherence to relevant policies, standards, and regulations. Please don't repete anything that's already mentioned by the QAAgent, i.e. <<{QAAgentOutput}>>"
    RecommendationAgentPrompt = "Reviews the document for recommendations."


    # Sample code assumes all relevant packages have already been imported:


    def json_to_memory(file_path):
    """
    Reads a JSON file from desktop and stores it in memory as a Python dictionary.
    """
    with open(file_path, 'r', encoding='utf-8') as file:
    json_data = json.load(file)
    return json_data
    precedence_mitigation_json = json.dumps(json_to_memory(FilePath))

    QAAgent = LlmAgent(
    name = "QAAgent",
    model = "gemini-2.0-flash",
    instructions = QAAgentPrompt,
    output_schema = final_output_json,
    output_key="QAAgentOutput"
    )

    ComplianceAgent = LlmAgent(
    name = "ComplianceAgent",
    model = "gemini-2.0-flash",
    input_schema = precedence_mitigation_json,
    instructions = ComplianceAgentPrompt,
    output_schema = final_output_json,
    output_key="ComplianceAgentOutput"
    )

    RecommendationAgent = LlmAgent(
    name = "RecommendationAgent",
    model = "gemini-2.0-flash",
    instructions = RecommendationAgentPrompt,
    output_schema = final_output_json,
    output_key="RecommendationAgentOutput"
    )

    root_agent = SequentialAgent(
    name = "RootAgent",
    model = "gemini-2.0-flash",
    subagents = [QAAgent, ComplianceAgent, RecommendationAgent]
    )


    Some sample data for precedence_mitigation_json is as belows:

    [
    {
    "States": "California, Nevada, Idaho",
    "Counties": "Sierra, Humboldt",
    "Category": "Economic Noise",
    "Risks": "Potential impacts to local communities.",
    "Mitigation": "Implement monitoring and community engagement",
    "Precedence": "Relevant federal and state regulations and guidelines cited."
    }
    ]


    The type of precedence_mitigation_json is read in as <class 'str'>

    The detailed error message is

    pydantic_core._pydantic_core.ValidationError: 2 validation errors for LlmAgentoutput_schemaInput should be a subclass of BaseModel [type=is_subclass_of, input_value='\n{\n "passing": "boo...": boolean\n },\n}\n', input_type=str]For further information visit https://errors.pydantic.dev/2.11/v/is_subclass_ofinstructionsExtra inputs are not permitted [type=extra_forbidden, input_value='Checks the information f...eness, and consistency.', input_type=str]For further information visit https://errors.pydantic.dev/2.11/v/extra_forbidden


    I tried different ways to reformat the precedence_mitigation_json but none of it works.

    Continue reading...

Compartilhe esta Página