Skip to content

[BUG] Pydantic Validation error while saving in Memory #4509

@sayoojbkumar

Description

@sayoojbkumar

Description

Getting the following Pydantic error while saving to memory.

ERROR:root:OpenAI API call failed: 1 validation error for TaskEvaluation
  Invalid JSON: expected value at line 1 column 1 [type=json_invalid, input_value='```json\n{\n  "assessmen...  ]\n    }\n  ]\n}\n```', input_type=str]
    For further information visit https://errors.pydantic.dev/2.11/v/json_invalid
[2026-02-18 18:17:49][ERROR]: Failed to add to long term memory: Failed to convert text into a Pydantic model due to validation error: 1 validation error for TaskEvaluation
  Invalid JSON: expected value at line 1 column 1 [type=json_invalid, input_value='```json\n{\n  "assessmen...  ]\n    }\n  ]\n}\n```', input_type=str]
    For further information visit https://errors.pydantic.dev/2.11/v/json_invalid
Image

Steps to Reproduce

  1. Run the POC code below.
  2. Go through the console logs.
from crewai import Agent, Task, Crew, Process
import os
from dotenv import load_dotenv

# Define agents
load_dotenv()
researcher = Agent(
    role="Senior Researcher",
    goal="Find comprehensive information on the given topic",
    backstory="You are an experienced researcher skilled at finding relevant information.",
    verbose=True,
)

writer = Agent(
    role="Report Writer",
    goal="Create a well-structured report based on research findings",
    backstory="You are a skilled writer who turns research into clear reports.",
    verbose=True,
)

# Define tasks
research_task = Task(
    description="Research the topic: {topic}",
    expected_output="A list of key findings about the topic.",
    agent=researcher,
)

writing_task = Task(
    description="Write a report based on the research findings.",
    expected_output="A comprehensive report in markdown format.",
    agent=writer,
    context=[research_task],
)

# Create crew with memory enabled and a custom embedding model
crew = Crew(
    agents=[researcher, writer],
    tasks=[research_task, writing_task],
    process=Process.sequential,
    memory=True,
    embedder={
        "provider": "openai",
        "config": {
            "model_name": "text-embedding-3-small",
            "api_key":os.getenv("API_KEY"),
            "api_base": os.getenv("BASE_URL")
        },
    },
    verbose=True,
)

# Kick off the crew
result = crew.kickoff(inputs={"topic": "AI in Healthcare"})
print(result.raw)

Expected behavior

CrewAI should successfully parse LLM output and save task evaluations to long-term memory without validation errors.

Screenshots/Code snippets

Image

Operating System

macOS Sonoma

Python Version

3.10

crewAI Version

1.9.3

crewAI Tools Version

1.9.3

Virtual Environment

Venv

Evidence

.

Possible Solution

.

Additional context

I am already aware of the following issues, and I am on the latest version of CrewAI. It looks like this hasn’t been resolved yet:

#3915

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions