Skip to content

Automate browser based workflows with AI

fix: show clear validation error for invalid JSON in HTTP Request Block (#SKY-7119) (#4978)

Celal Zamanoğlu96ee537d982a
diff --git a/skyvern-frontend/src/routes/workflows/editor/nodes/HttpRequestNode/httpValidation.test.ts b/skyvern-frontend/src/routes/workflows/editor/nodes/HttpRequestNode/httpValidation.test.ts
new file mode 100644
index 000000000..ea6e8521a
--- /dev/null
+++ b/skyvern-frontend/src/routes/workflows/editor/nodes/HttpRequestNode/httpValidation.test.ts
@@ -0,0 +1,115 @@
+import { validateJson, validateUrl } from "./httpValidation";
+import { describe, test, expect } from "vitest";
+
+describe("validateJson", () => {
+ test("empty string is valid with null message", () => {
+ expect(validateJson("")).toEqual({ valid: true, message: null });
+ });
+
+ test("whitespace-only string is valid with null message", () => {
+ expect(validateJson(" ")).toEqual({ valid: true, message: null });
+ });
+
+ test("empty object is valid with null message", () => {
+ expect(validateJson("{}")).toEqual({ valid: true, message: null });
+ });
+
+ test("empty array is valid with null message", () => {
+ expect(validateJson("[]")).toEqual({ valid: true, message: null });
+ });
+
+ test("valid JSON object returns valid", () => {
+ const result = validateJson('{"key": "value"}');
+ expect(result.valid).toBe(true);
+ expect(result.message).toBe("Valid JSON");
+ });
+
+ test("quoted template placeholder is valid JSON", () => {
+ const result = validateJson('{"url": "{{ webhook_url }}"}');
+ expect(result.valid).toBe(true);
+ expect(result.message).toBe("Valid JSON");
+ });
+
+ test("multiple quoted templates are valid", () => {
+ const result = validateJson(
+ '{"first": "{{ first_name }}", "last": "{{ last_name }}"}',
+ );
+ expect(result.valid).toBe(true);
+ expect(result.message).toBe("Valid JSON");
+ });
+
+ test("unquoted template placeholder is invalid with actionable message", () => {
+ const result = validateJson('{"url": {{ webhook_url }}}');
+ expect(result.valid).toBe(false);
+ expect(result.message).toContain(
+ "Template placeholders must be wrapped in quotes",
+ );
+ });
+
+ test("unquoted template in value position is invalid", () => {
+ const result = validateJson(
+ '{"first": {{ patient_first_name }}, "last": "Doe"}',
+ );
+ expect(result.valid).toBe(false);
+ expect(result.message).toContain(
+ "Template placeholders must be wrapped in quotes",
+ );
+ });
+
+ test("trailing comma is invalid", () => {
+ const result = validateJson('{"key": "value",}');
+ expect(result.valid).toBe(false);
+ });
+
+ test("completely malformed JSON is invalid", () => {
+ const result = validateJson("{key: value}");
+ expect(result.valid).toBe(false);
+ });
+
+ test("unclosed brace is invalid", () => {
+ const result = validateJson('{"key": "value"');
+ expect(result.valid).toBe(false);
+ });
+
+ test("valid JSON with quoted template and other values is valid", () => {
+ const result = validateJson('{"inner": "{{ param }}", "num": 42}');
+ expect(result.valid).toBe(true);
+ expect(result.message).toBe("Valid JSON");
+ });
+
+ test("JSON array with valid content is valid", () => {
+ const result = validateJson('["a", "b", "{{ param }}"]');
+ expect(result.valid).toBe(true);
+ expect(result.message).toBe("Valid JSON");
+ });
+});
+
+describe("validateUrl", () => {
+ test("empty URL is invalid", () => {
+ const result = validateUrl("");
+ expect(result.valid).toBe(false);
+ expect(result.message).toBe("URL is required");
+ });
+
+ test("valid http URL is valid", () => {
+ const result = validateUrl("http://example.com");
+ expect(result.valid).toBe(true);
+ });
+
+ test("valid https URL is valid", () => {
+ const result = validateUrl("https://example.com/api");
+ expect(result.valid).toBe(true);
+ });
+
+ test("non-http protocol is invalid", () => {
+ const result = validateUrl("ftp://example.com");
+ expect(result.valid).toBe(false);
+ expect(result.message).toBe("URL must use HTTP or HTTPS protocol");
+ });
+
+ test("malformed URL is invalid", () => {
+ const result = validateUrl("not a url");
+ expect(result.valid).toBe(false);
+ expect(result.message).toBe("Invalid URL format");
+ });
+});
diff --git a/skyvern-frontend/src/routes/workflows/editor/nodes/HttpRequestNode/httpValidation.ts b/skyvern-frontend/src/routes/workflows/editor/nodes/HttpRequestNode/httpValidation.ts
index 61080b476..23c9abd46 100644
--- a/skyvern-frontend/src/routes/workflows/editor/nodes/HttpRequestNode/httpValidation.ts
+++ b/skyvern-frontend/src/routes/workflows/editor/nodes/HttpRequestNode/httpValidation.ts
@@ -28,9 +28,24 @@ export function validateJson(value: string): {
return { valid: true, message: null };
}
- const result = TSON.parse(trimmed);
- if (result.success) {
- return { valid: true, message: "Valid JSON" };
+ // First check: does it pass TSON (template-aware) parsing?
+ const tsonResult = TSON.parse(trimmed);
+ if (!tsonResult.success) {
+ return { valid: false, message: tsonResult.error || "Invalid JSON" };
}
- return { valid: false, message: result.error || "Invalid JSON" };
+
+ // Second check: does it also pass strict JSON parsing?
+ // If TSON passes but JSON.parse fails, the input contains unquoted {{ }} placeholders.
+ // The backend expects template placeholders to be quoted strings, so this is always an error.
+ try {
+ JSON.parse(trimmed);
+ } catch {
+ return {
+ valid: false,
+ message:
+ 'Template placeholders must be wrapped in quotes, e.g. "{{ parameter }}"',
+ };
+ }
+
+ return { valid: true, message: "Valid JSON" };
}
diff --git a/skyvern-frontend/src/routes/workflows/editor/workflowEditorUtils.ts b/skyvern-frontend/src/routes/workflows/editor/workflowEditorUtils.ts
index 367bd042e..9661e15ff 100644
--- a/skyvern-frontend/src/routes/workflows/editor/workflowEditorUtils.ts
+++ b/skyvern-frontend/src/routes/workflows/editor/workflowEditorUtils.ts
@@ -4193,7 +4193,7 @@ function getWorkflowErrors(nodes: Array<AppNode>): Array<string> {
jsonFields.forEach(({ value, name }) => {
const result = validateJson(value);
if (!result.valid && result.message) {
- errors.push(`${node.data.label}: ${name} is not valid JSON.`);
+ errors.push(`${node.data.label}: ${name} - ${result.message}`);
}
});
});
@@ -4205,7 +4205,7 @@ function getWorkflowErrors(nodes: Array<AppNode>): Array<string> {
}
const payloadResult = validateJson(node.data.payload);
if (!payloadResult.valid && payloadResult.message) {
- errors.push(`${node.data.label}: Payload is not valid JSON.`);
+ errors.push(`${node.data.label}: Payload - ${payloadResult.message}`);
}
});