# Validation Error When Initializing Short-Term and Long-Term Memory in CrewAI

**URL:** <https://community.crewai.com/t/validation-error-when-initializing-short-term-and-long-term-memory-in-crewai/4902>\
**Category:** CrewAI Community Support\
**Tags:** crewai\
**Created:** [March 22, 2025, 10:21am UTC](https://community.crewai.com/t/validation-error-when-initializing-short-term-and-long-term-memory-in-crewai/4902 "2025-03-22T10:21:21Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rajesh\_thangaraj](https://sea1.discourse-cdn.com/flex025/user_avatar/community.crewai.com/rajesh_thangaraj/32/3153_2.png) [@Rajesh\_thangaraj](https://community.crewai.com/u/Rajesh_thangaraj)\
**Post date:** [March 22, 2025, 10:21am UTC](https://community.crewai.com/t/validation-error-when-initializing-short-term-and-long-term-memory-in-crewai/4902/1 "2025-03-22T10:21:21Z")

</div>

I am encountering a validation error when trying to configure short-term and long-term memory in CrewAI using custom embeddings. Even after disabling long-term memory (`long_term_memory=None`), the error persists. The issue seems to be related to the `TaskEvaluation` model validation.

crew = Crew(  
agents=[summarizer\_agent, rag\_chat\_agent, general\_chat\_agent],  
tasks=[chat\_task],  
process=Process.hierarchical,  
verbose=True,  
max\_iter=3,  
manager\_agent=manager\_agent,  
memory=True,  
embedder={  
“provider”: “custom”,  
“config”: {  
“embedder”: SentenceTransformerEmbedder(EMBEDDING\_MODEL\_PATH)  
}  
},  
short\_term\_memory=ShortTermMemory(  
storage=RAGStorage(  
embedder\_config={  
“provider”: “custom”,  
“config”: {  
“embedder”: SentenceTransformerEmbedder(EMBEDDING\_MODEL\_PATH)  
}  
},  
type=“short\_term”,  
path=SHORT\_TERM\_PATH  
)  
),  
long\_term\_memory=LongTermMemory(  
storage=LTMSQLiteStorage(  
db\_path=LONG\_TERM\_PATH  
)  
),  
)  
**Error Message:**  
I receive the following error when running the code:

Failed to add to long term memory: Failed to convert text into a Pydantic model due to the following error: 3 validation errors for TaskEvaluation  
suggestions  
Field required [type=missing, input\_value={‘task\_description’: ‘{“d… of France is Paris.”}’}, input\_type=dict]  
For further information visit [Redirecting...](https://errors.pydantic.dev/2.10/v/missing)  
quality

Field required [type=missing, input\_value={‘task\_description’: ‘{“d… of France is Paris.”}’}, input\_type=dict]

**What I’ve Tried:**

1. Tried setting `long_term_memory=None` —\> Same error persists. so pls any one faced same issue give the soliton my crew ai everying recent version crewai 0.102

---

<div class="post-metadata">

**Author:** ![maxmoura](https://sea1.discourse-cdn.com/flex025/user_avatar/community.crewai.com/maxmoura/32/4206_2.png) [@maxmoura](https://community.crewai.com/u/maxmoura)\
**Post date:** [March 22, 2025, 11:22am UTC](https://community.crewai.com/t/validation-error-when-initializing-short-term-and-long-term-memory-in-crewai/4902/2 "2025-03-22T11:22:53Z")

</div>

Hi, Rajesh! I suggest that you post here the parameters that you are using for your `chat_task`. It’s also important to present the definition of the `BaseModel` that you’re passing to the `output_pydantic` parameter of that task.

---

<div class="post-metadata">

**Author:** ![Rajesh\_thangaraj](https://sea1.discourse-cdn.com/flex025/user_avatar/community.crewai.com/rajesh_thangaraj/32/3153_2.png) [@Rajesh\_thangaraj](https://community.crewai.com/u/Rajesh_thangaraj)\
**Post date:** [March 22, 2025, 1:59pm UTC](https://community.crewai.com/t/validation-error-when-initializing-short-term-and-long-term-memory-in-crewai/4902/3 "2025-03-22T13:59:31Z")

</div>

def create\_autonomous\_task(user\_query: str):  
has\_document = “collection” in st.session\_state  
return Task(  
description=f"""Analyze and process the user query:  
User Query: {user\_query}  
Document Status: {‘Uploaded’ if has\_document else ‘Not Uploaded’}  
{user\_query}

```
    Available agent specializations:
    1. Document Summarization Expert - .docx/.pdf summaries
    2. Document Analysis Specialist - Document content questions
    3. Conversational Assistant - General chat

    Routing Rules:
    1. If query contains "summarize" and document exists -> Summarizer
    2. If document exists and question references content -> Document Analyst
    3. All other cases -> General Chat
    """,
    expected_output="Immediate, final response prefixed with 'Final Answer:'",
    context=[{
        "has_document": has_document,
        "query": user_query,
        "description": user_query,
        "expected_output": "Relevant response matching query intent"
    }],
    config={
        "allow_delegation": True,
        "stop_on_success": True
    }
)

```

chat\_task = create\_autonomous\_task(user\_input)

I’m not using `output_pydantic` directly — could that be the issue? Should I define a specific `BaseModel` for the `output_pydantic` field to satisfy Pydantic’s validation?

---

<div class="post-metadata">

**Author:** ![Rajesh\_thangaraj](https://sea1.discourse-cdn.com/flex025/user_avatar/community.crewai.com/rajesh_thangaraj/32/3153_2.png) [@Rajesh\_thangaraj](https://community.crewai.com/u/Rajesh_thangaraj)\
**Post date:** [March 22, 2025, 2:07pm UTC](https://community.crewai.com/t/validation-error-when-initializing-short-term-and-long-term-memory-in-crewai/4902/4 "2025-03-22T14:07:52Z")

</div>

If I set `memory=False`, I immediately get a response. However, when I set `memory=True` with the following `short_term_memory` configuration:

short\_term\_memory=ShortTermMemory(  
storage=RAGStorage(  
embedder\_config={  
“provider”: “custom”,  
“config”: {  
“embedder”: SentenceTransformerEmbedder(EMBEDDING\_MODEL\_PATH)  
}  
},  
type=“short\_term”,  
path=SHORT\_TERM\_PATH  
)  
)  
I still get the following error, even if `long_term_memory=None`:

Failed to add to long term memory: Failed to convert text into a Pydantic model due to the following error: 3 validation errors for TaskEvaluation  
suggestions  
Field required [type=missing, input\_value={‘task\_description’: ‘{“d… of France is Paris.”}’}, input\_type=dict]  
For further information visit [Redirecting...](https://errors.pydantic.dev/2.10/v/missing)  
quality  
Field required [type=missing, input\_value={‘task\_description’: ‘{“d… of France is Paris.”}’}, input\_type=dict]  
For further information visit [Redirecting...](https://errors.pydantic.dev/2.10/v/missing)  
entities

```
For further information visit https://errors.pydantic.dev/2.10/v/missing

```

To fix this, I tried adding `long_term_memory` with the following configuration:

long\_term\_memory=LongTermMemory(  
storage=LTMSQLiteStorage(  
db\_path=LONG\_TERM\_PATH  
)  
)  
However, the issue persists. I am using a custom embedding model with the following class:

class SentenceTransformerEmbedder(EmbeddingFunction):  
def **init** (self, model\_path: str):  
self.model = SentenceTransformer(model\_path)  
super(). **init** ()

```
def __call__ (self, input: Documents) -> EMD:
    return self.model.encode(input).tolist()

def encode_documents(self, documents: List[str]) -> List[List[float]]:
    return self.model.encode(documents).tolist()

def encode_queries(self, queries: List[str]) -> List[List[float]]:
    return self.model.encode(queries).tolist()

```

---

<div class="post-metadata">

**Author:** ![maxmoura](https://sea1.discourse-cdn.com/flex025/user_avatar/community.crewai.com/maxmoura/32/4206_2.png) [@maxmoura](https://community.crewai.com/u/maxmoura)\
**Post date:** [March 22, 2025, 7:47pm UTC](https://community.crewai.com/t/validation-error-when-initializing-short-term-and-long-term-memory-in-crewai/4902/5 "2025-03-22T19:47:45Z")

</div>

Wow, lots of things going on here. I swear I did my best to understand and contribute. After reformatting your code and evaluating the scenario you presented, these are my considerations:

1. The `context` parameter does indeed exist in a `Task`. However, let’s look at what the documentation says about this parameter: “Other tasks whose outputs will be used as context for this task.” Basically, you’ll use it when your current task depends on the output of a previous task (it can be omitted in the case of `Process.sequential`). I suggest you review [the documentation on tasks](https://docs.crewai.com/concepts/tasks), especially the “Task Attributes” section.
2. The `config` parameter does indeed exist in a `Task`. However, I don’t see the point of using it in your use case, since the information you were trying to pass can simply be included in the `description` of your task (see how I included it in the reformatted version that I present below).
3. It wasn’t clear if you’re trying to implement a hierarchical `Process`. If that’s the case, I suggest you review [the documentation on processes](https://docs.crewai.com/concepts/processes), especially on “Hierarchical Process”. I also suggest [reading this thread](https://community.crewai.com/t/manager-agent-delegates-task-to-wrong-agent-in-a-hierarchical-process/3179) on the subject.
4. As for the use of `Memory`, I suggest you review [the documentation on the subject](https://docs.crewai.com/concepts/memory), especially the sections that exemplify customizations.
5. Finally, I suggest that you first successfully execute a super simplified version of the solution you’re proposing, trying to ensure that each small part of your solution is working as you want, and then increase the complexity to meet your effective use case.

Here’s the version of your code that I reformatted as I understood it:

```python
def create_autonomous_task(user_query: str):
    has_document = "collection" in st.session_state
    document_status = "Uploaded" if has_document else "Not Uploaded"

    return Task(
        description=(f"""
            Analyze and process the user query:

            User Query: {user_query}

            Available agent specializations:
            1. Document Summarization Expert - .docx/.pdf summaries
            2. Document Analysis Specialist - Document content questions
            3. Conversational Assistant - General chat

            Routing Rules:
            1. If query contains "summarize" and document exists -> Summarizer
            2. If document exists and question references content -> Document Analyst
            3. All other cases -> General Chat

            Context:
            - Document Status: {document_status}
            - Document Exists: {has_document}
        """),
        expected_output="Immediate, final response prefixed with 'Final Answer:'"
    )

chat_task = create_autonomous_task(user_input)

```
