From 3f1f663ea71a6605a2f618fabc4e2e1ef5bc7b03 Mon Sep 17 00:00:00 2001 From: Zamil Majdy Date: Tue, 20 Jan 2026 23:09:45 -0500 Subject: [PATCH] fix(backend): handle null values in GraphSettings validation Fixes AUTOGPT-SERVER-76H When parsing LibraryAgent settings from the database, null values for human_in_the_loop_safe_mode and sensitive_action_safe_mode were causing Pydantic validation errors. This adds BeforeValidator annotations to coerce null values to their defaults (True and False respectively). --- autogpt_platform/backend/backend/data/graph.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/autogpt_platform/backend/backend/data/graph.py b/autogpt_platform/backend/backend/data/graph.py index d868c0ff3b..d70bdbdc61 100644 --- a/autogpt_platform/backend/backend/data/graph.py +++ b/autogpt_platform/backend/backend/data/graph.py @@ -3,7 +3,7 @@ import logging import uuid from collections import defaultdict from datetime import datetime, timezone -from typing import TYPE_CHECKING, Any, Literal, Optional, cast +from typing import TYPE_CHECKING, Annotated, Any, Literal, Optional, cast from prisma.enums import SubmissionStatus from prisma.models import ( @@ -20,7 +20,7 @@ from prisma.types import ( AgentNodeLinkCreateInput, StoreListingVersionWhereInput, ) -from pydantic import BaseModel, Field, create_model +from pydantic import BaseModel, BeforeValidator, Field, create_model from pydantic.fields import computed_field from backend.blocks.agent import AgentExecutorBlock @@ -62,8 +62,14 @@ logger = logging.getLogger(__name__) class GraphSettings(BaseModel): - human_in_the_loop_safe_mode: bool = True - sensitive_action_safe_mode: bool = False + # Use Annotated with BeforeValidator to coerce None to default values. + # This handles cases where the database has null values for these fields. + human_in_the_loop_safe_mode: Annotated[ + bool, BeforeValidator(lambda v: v if v is not None else True) + ] = True + sensitive_action_safe_mode: Annotated[ + bool, BeforeValidator(lambda v: v if v is not None else False) + ] = False @classmethod def from_graph(