feat: add validation for required fields and improve agent creation logic

This commit is contained in:
Siddhant Rai
2025-07-12 12:30:00 +05:30
parent 2e7cb510ae
commit a472ee7602
6 changed files with 144 additions and 40 deletions

View File

@@ -80,7 +80,7 @@ def check_required_fields(data, required_fields):
jsonify(
{
"success": False,
"message": f"Missing fields: {', '.join(missing_fields)}",
"message": f"Missing required fields: {', '.join(missing_fields)}",
}
),
400,
@@ -88,6 +88,29 @@ def check_required_fields(data, required_fields):
return None
def validate_required_fields(data, required_fields):
missing_fields = []
empty_fields = []
for field in required_fields:
if field not in data:
missing_fields.append(field)
elif not data[field]:
empty_fields.append(field)
errors = []
if missing_fields:
errors.append(f"Missing required fields: {', '.join(missing_fields)}")
if empty_fields:
errors.append(f"Empty values in required fields: {', '.join(empty_fields)}")
if errors:
return make_response(
jsonify({"success": False, "message": " | ".join(errors)}), 400
)
return None
def get_hash(data):
return hashlib.md5(data.encode(), usedforsecurity=False).hexdigest()