# Pydantic output

**URL:** <https://community.crewai.com/t/pydantic-output/1379>\
**Category:** Crews\
**Tags:** output\_issues, crewai\
**Created:** [November 13, 2024, 10:04am UTC](https://community.crewai.com/t/pydantic-output/1379 "2024-11-13T10:04:02Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Bilal\_Ahmad](https://sea1.discourse-cdn.com/flex025/user_avatar/community.crewai.com/bilal_ahmad/32/1002_2.png) [@Bilal\_Ahmad](https://community.crewai.com/u/Bilal_Ahmad)\
**Post date:** [November 13, 2024, 10:04am UTC](https://community.crewai.com/t/pydantic-output/1379/1 "2024-11-13T10:04:02Z")

</div>

would you please help me to get output in pydantic format for following agent task

from typing import List, Dict  
from pydantic import BaseModel, Field

class CampaignIdea(BaseModel):  
post\_title: str = Field(…, description=“Title for the post”)  
media\_type: str = Field(…, description=“Media Type (e.g., Blog, Video)”)  
description: str = Field(…, description=“Brief description of the post content”)

class Campaign(BaseModel):  
title: str = Field(…, description=“Campaign title”)  
content\_focus: str = Field(…, description=“Briefly describe the main focus”)  
campaign\_ideas: List[CampaignIdea] = Field(…, description=“List of campaign ideas”)

class ContentStrategy(BaseModel):  
strategy: Dict[str, Campaign] = Field(…, description=“Dictionary of campaigns keyed by campaign ID, starting from 1”)

# Define the agent

content\_strategy\_agent = Agent(  
role=“Employer Brand Content Strategist”,  
goal=“Create a content strategy that enhances {company}'s employer brand by leveraging employee sentiment data. Focus on attracting new talent by showcasing {company}'s strengths and addressing any negative perceptions.”,  
backstory=“An experienced brand strategist skilled in using sentiment data to develop targeted content strategies for talent attraction, emphasizing {company}'s strengths and addressing areas for improvement.”,  
verbose=True,  
max\_iter=3  
)

# Define the task

content\_strategy\_task = Task(  
description=“”"Given sentiment data about {company}:  
- Create a content plan to showcase {company}'s strengths and address any concerns to attract new talent.  
- For each sentiment theme (e.g., work culture, management, benefits, etc.), provide content ideas that emphasize {company}'s positive aspects and effectively address areas needing improvement.

````
Each content idea should include:
- **Title** : A catchy title or theme for the content or campaign.
- **Content Focus** : Briefly describe the focus of the content (e.g., promoting work-life balance or highlighting benefits, etc).
- **Campaign Ideas** : Specific content ideas with post titles, recommended media types, and content overview/description.

Sentiment Data:
{sentiments}
""",

expected_output="""The output should be a structured JSON content strategy for {company} in the following format:
```josn{{
    "1":{{
        "title":// Campaign title, e.g., "Highlighting Positive Work Culture"
        "content_focus": // Briefly describe the main focus, e.g., emphasize {company}'s supportive culture and work-life balance etc.
        "campaign_ideas":[ // List of dictionary contains compaign ideas
            {{
                "post_title": // Title for the post,
                "media_type"://Media Type (e.g., Blog, Video),
                "description", // Brief description of the post content.
            }}
            ...
        ]
    }}
    "2":{{
    ...
    }}
    ...

}}```
Note: Do not add any pre or post text; directly provide JSON output,
and ensure each section aligns with the provided sentiment data, highlighting {company}'s strengths and addressing any concerns without adding extra context.

""",
    
output_pydantic = ContentStrategy,
agent=content_strategy_agent

````

)

content\_strategist\_crew = Crew(  
agents=[content\_strategy\_agent],  
tasks=[  
content\_strategy\_task  
],  
verbose=2,

)

content\_strategist\_input = {  
‘company’:company\_name,  
‘sentiments’:company\_sentiments  
}

content\_strategist\_response = content\_strategist\_crew.kickoff(inputs=content\_strategist\_input)

---

<div class="post-metadata">

**Author:** ![rokbenko](https://sea1.discourse-cdn.com/flex025/user_avatar/community.crewai.com/rokbenko/32/492_2.png) [@rokbenko](https://community.crewai.com/u/rokbenko)\
**Post date:** [November 13, 2024, 11:08am UTC](https://community.crewai.com/t/pydantic-output/1379/2 "2024-11-13T11:08:04Z")

</div>

@Bilal_Ahmad Set the `output_pydantic` to `True` to the task. See the official [docs](https://docs.crewai.com/concepts/tasks#task-attributes).

---

<div class="post-metadata">

**Author:** ![Bilal\_Ahmad](https://sea1.discourse-cdn.com/flex025/user_avatar/community.crewai.com/bilal_ahmad/32/1002_2.png) [@Bilal\_Ahmad](https://community.crewai.com/u/Bilal_Ahmad)\
**Post date:** [November 13, 2024, 4:46pm UTC](https://community.crewai.com/t/pydantic-output/1379/3 "2024-11-13T16:46:07Z")

</div>

But I don’t see pydantic output, even if i provide Pydantic model in output\_pydantic key

---

<div class="post-metadata">

**Author:** ![rokbenko](https://sea1.discourse-cdn.com/flex025/user_avatar/community.crewai.com/rokbenko/32/492_2.png) [@rokbenko](https://community.crewai.com/u/rokbenko)\
**Post date:** [November 13, 2024, 5:04pm UTC](https://community.crewai.com/t/pydantic-output/1379/4 "2024-11-13T17:04:05Z")

</div>

@Bilal_Ahmad Are you using the OpenAI client?
