fix(backend): Cleanup on validation logic for AgentExecutorBlock & SmartDecisionMakerBlock

This commit is contained in:
Zamil Majdy
2025-03-02 18:17:01 +07:00
parent 36447a0c58
commit ef00ab51e0
4 changed files with 6 additions and 3 deletions

View File

@@ -58,7 +58,7 @@ class AgentExecutorBlock(Block):
return set(required_fields) - set(data)
@classmethod
def validate_data(cls, data: BlockInput) -> str | None:
def get_mismatch_error(cls, data: BlockInput) -> str | None:
return json.validate_with_jsonschema(cls.get_input_schema(data), data)
class Output(BlockSchema):

View File

@@ -396,4 +396,3 @@ class SmartDecisionMakerBlock(Block):
response.prompt.append(response.raw_response)
yield "conversations", response.prompt
yield "length", len(response.prompt)

View File

@@ -114,6 +114,10 @@ class BlockSchema(BaseModel):
def validate_data(cls, data: BlockInput) -> str | None:
return json.validate_with_jsonschema(schema=cls.jsonschema(), data=data)
@classmethod
def get_mismatch_error(cls, data: BlockInput) -> str | None:
return cls.validate_data(data)
@classmethod
def validate_field(cls, field_name: str, data: BlockInput) -> str | None:
"""

View File

@@ -435,7 +435,7 @@ def validate_exec(
return None, f"{error_prefix} missing input {missing_input}"
# Last validation: Validate the input values against the schema.
if error := schema.validate_data(data):
if error := schema.get_mismatch_error(data):
error_message = f"{error_prefix} {error}"
logger.error(error_message)
return None, error_message