Find answers from the community

Updated 6 days ago

Structured Representation of Curriculum Competencies

Hi everyone, I am struggling to safe an agent response from a tool in the following PydanticBase Model:

class LehrplanCompetencyMap(BaseModel):
""" Strukturierte Darstellung der Kompetenzen eines Lehrplans """
school_state: str = Field("", description="Bundesland des Lehrplans")
school_level: str = Field("", description="Schulstufe des Lehrplans")
class_level: int = Field(0, description="Angegebene Klassenstufe")
subject_competencies: Dict[str, Dict[str, List[str]]] = Field(
default_factory=Dict, description="Strukturierte Darstellung der Kompetenzen eines Lehrplans")

Running agentic workflow with the tool:
async def query_lehrplan_competencies(ctx: Context, query: str) -> LehrplanCompetencyMap:
"Extrahiert Kompetenzen aus dem Lehrplan und speichert sie Schema im Context State."
response = await lehrplaene_engine.aquery(query)
try:
lehrplan_data = LehrplanCompetencyMap.model_validate(response)
except Exception as e:
print(f"Fehler beim Parsen der Lehrplan-Daten: {e}")
return LehrplanCompetencyMap()
current_state = await ctx.get("state")
if "lehrplan_data" not in current_state:
current_state["lehrplan_data"] = {}
if "subject_competencies" not in current_state["lehrplan_data"]:
current_state["lehrplan_data"]["subject_competencies"] = {}
current_state["lehrplan_data"] = lehrplan_data.model_dump()
await ctx.set("state", current_state)
return lehrplan_data # Rückgabe des Pydantic-Modells

The subject comptency is not stored properly in the PydanticModel & context with this error:
🔧 Tool Result (query_lehrplan_competencies):
Arguments: {'query': 'Mathematik 2. Klasse Bayern'}
Output: 1 validation error for LehrplanCompetencyMap
Invalid JSON: expected value at line 1 column 1 [type=json_invalid, input_value='Type Dict cannot be instted; use dict() instead', input_type=str] For further information visit https://errors.pydantic.dev/2.8/v/json_invalid
L
v
9 comments
Its really hard to tell, but you'll need to give the complete full traceback to see what the issue actually is
thats the traceback
ohhh, interesting, an error inside an error
input_value="1 validation error for L...antic.dev/2.8/v/missing"
what LLM are you using? Seems like its just writing invalid JSON? Maybe?

Type Dict cannot be instted; use dict() instead also sounds weird, not sure where thats coming from
Maybe update pydantic? To confirm, you did from pydantic import BaseModel when defiing your output_cls?
Update, but still same error...How is the Agent tool working actually, is it converting the LLM response directly to the PyDantic model or what is happening under the hood?
if there is a validation error, the query engine is dumping the validation error as text I think
Add a reply
Sign up and join the conversation on Discord