<@ULVA73B9P> why am getting a pydantic_core._pydan...
# ask-marvin
m
@Marvin why am getting a pydantic_core._pydantic_core.ValidationError: 1 validation error for CloudRunWorkerJobV2Configuration job_body Value error, Job body is missing required components: /template [type=value_error, input_value={'kind': 'Job', 'spec': {...launch-stage': 'BETA'}}}, input_type=dict] For further information visit https://errors.pydantic.dev/2.11/v/value_error for the following config
Copy code
"job_configuration": {
    "env": "{{ env }}",
    "name": "{{ name }}",
    "labels": "{{ labels }}",
    "region": "{{ region }}",
    "command": "{{ command }}",
    "timeout": "{{ timeout }}",
    "job_body": {
      "kind": "Job",
      "spec": {
        "template": {
          "spec": {
            "template": {
              "spec": {
                "containers": [
                  {
                    "image": "{{ image }}",
                    "command": "{{ command }}",
                    "resources": {
                      "limits": {
                        "cpu": "{{ cpu }}",
                        "memory": "{{ memory }}"
                      },
                      "requests": {
                        "cpu": "{{ cpu }}",
                        "memory": "{{ memory }}"
                      }
                    }
                  }
                ],
                "timeoutSeconds": "{{ timeout }}",
                "serviceAccountName": "{{ service_account_name }}"
              }
            }
          },
          "metadata": {
            "name": "{{ name }}",
            "annotations": {
              "<http://run.googleapis.com/cloudsql-instances|run.googleapis.com/cloudsql-instances>": "{{ cloudsql_instance }}"
            }
          }
        }
      },
      "metadata": {
        "name": "{{ name }}",
        "annotations": {
          "<http://run.googleapis.com/launch-stage|run.googleapis.com/launch-stage>": "BETA",
          "<http://run.googleapis.com/vpc-access-connector|run.googleapis.com/vpc-access-connector>": "{{ vpc_connector_name }}"
        }
      },
      "apiVersion": "<http://run.googleapis.com/v1|run.googleapis.com/v1>"
    }
m
thought for 336.1 seconds
You’re hitting that ValidationError because the Cloud Run v2 worker expects a top-level template in the job_body, but your payload nests it under spec. The validator is literally looking for /template at the root of job_body and can’t find it. A few other gotchas I see: - Don’t quote templated values that aren’t strings (e.g., env, labels, command) — quoting them turns lists/dicts into strings and can cause type issues later. - Slack auto-linking in your JSON keys will break things. Use run.googleapis.com/… not <http://…|…>. - For Cloud Run v2, use serviceAccount (not serviceAccountName) and timeout as a duration string like "600s" in the template. Here’s a minimal job_configuration skeleton that matches what the CloudRunWorkerJobV2Configuration expects. Note the top-level template, and unquoted non-string placeholders:
Copy code
"job_configuration": {
  "env": {{ env }},
  "name": "{{ name }}",
  "labels": {{ labels }},
  "region": "{{ region }}",
  "command": {{ command }},
  "timeout": "{{ timeout }}",
  "job_body": {
    "apiVersion": "<http://run.googleapis.com/v1|run.googleapis.com/v1>",
    "kind": "Job",
    "metadata": {
      "name": "{{ name }}",
      "annotations": {
        "<http://run.googleapis.com/launch-stage|run.googleapis.com/launch-stage>": "BETA",
        "<http://run.googleapis.com/vpc-access-connector|run.googleapis.com/vpc-access-connector>": "{{ vpc_connector_name }}"
      },
      "labels": {{ labels }}
    },
    "template": {
      "metadata": {
        "annotations": {
          "<http://run.googleapis.com/cloudsql-instances|run.googleapis.com/cloudsql-instances>": "{{ cloudsql_instance }}"
        }
      },
      "template": {
        "containers": [
          {
            "image": "{{ image }}",
            "command": {{ command }},
            "env": {{ env }},
            "resources": {
              "limits": {
                "cpu": "{{ cpu }}",
                "memory": "{{ memory }}"
              }
            }
          }
        ],
        "serviceAccount": "{{ service_account_name }}",
        "timeout": "{{ timeout }}"
      }
    }
  }
}
Notes: - If you need requests as well as limits, you can include them under resources, but Cloud Run v2 primarily respects limits. - timeout should be a duration string in the job template (e.g., "600s"). The top-level job_configuration.timeout can be your templated value that resolves to a duration string. - Keep the command as a list of strings, e.g., ["python", "-m", "prefect.engine"]. Docs for reference: - Prefect GCP worker guide - Workers concepts If this still errors, can you share: - Your versions of prefect and prefect-gcp (
pip show prefect prefect-gcp
) - The rendered job_body (with secrets redacted), to confirm types and keys after templating?
m
@Marvin This is my job configuration "job_configuration": { "env": "{{ env }}", "name": "{{ name }}", "labels": "{{ labels }}", "region": "{{ region }}", "command": "{{ command }}", "timeout": "{{ timeout }}", "job_body": { "kind": "Job", "spec": { "template": { "spec": { "template": { "spec": { "containers": [ { "image": "{{ image }}", "command": "{{ command }}", "resources": { "limits": { "cpu": "{{ cpu }}", "memory": "{{ memory }}" }, "requests": { "cpu": "{{ cpu }}", "memory": "{{ memory }}" } } } ], "timeoutSeconds": "{{ timeout }}", "serviceAccountName": "{{ service_account_name }}" } } }, "metadata": { "name": "{{ name }}", "annotations": { "run.googleapis.com/cloudsql-instances": "{{ cloudsql_instance }}" } } } }, "metadata": { "name": "{{ name }}", "annotations": { "run.googleapis.com/launch-stage": "BETA", "run.googleapis.com/vpc-access-connector": "{{ vpc_connector_name }}" } }, "apiVersion": "run.googleapis.com/v1" } But I am still getting the same error eported flow run '63cbe314-a52b-4cab-822a-115b5971d200' as crashed: Flow run could not be submitted to infrastructure: 1 validation error for CloudRunWorkerJobV2Configuration job_body Value error, Job body is missing required components: /template [type=value_error, input_value={'kind': 'Job', 'spec': {...'run.googleapis.com/v1'}, input_type=dict]
m
thought for 53.0 seconds
Thanks for sharing the full config — that helps. The error is happening because the Cloud Run v2 worker expects a top-level
template
field in
job_body
, but your payload is using a Kubernetes/Cloud Run v1-style
spec
nesting. The validator is literally looking for
/template
at the root of
job_body
and can’t find it. Additional issues I see: - You’re using v1 keys:
serviceAccountName
and
timeoutSeconds
. For Cloud Run v2, use
serviceAccount
and
timeout
(duration string like "600s"). - Slack auto-links in your annotation keys will break validation. Use plain keys like
<http://run.googleapis.com/vpc-access-connector|run.googleapis.com/vpc-access-connector>
(no
<...|...>
). - Don’t quote non-string placeholders such as
env
,
labels
, and
command
— quoting will turn them into strings instead of dicts/lists. Here’s a job_configuration that fits Cloud Run v2 and Prefect’s
CloudRunWorkerJobV2Configuration
expectations. Note the top-level
template
and the v2 keys:
Copy code
"job_configuration": {
  "env": {{ env }},
  "name": "{{ name }}",
  "labels": {{ labels }},
  "region": "{{ region }}",
  "command": {{ command }},
  "timeout": "{{ timeout }}",
  "job_body": {
    "kind": "Job",
    "metadata": {
      "name": "{{ name }}",
      "labels": {{ labels }},
      "annotations": {
        "<http://run.googleapis.com/launch-stage|run.googleapis.com/launch-stage>": "BETA"
      }
    },
    "template": {
      "metadata": {
        "annotations": {
          "<http://run.googleapis.com/cloudsql-instances|run.googleapis.com/cloudsql-instances>": "{{ cloudsql_instance }}",
          "<http://run.googleapis.com/vpc-access-connector|run.googleapis.com/vpc-access-connector>": "{{ vpc_connector_name }}"
        }
      },
      "template": {
        "containers": [
          {
            "image": "{{ image }}",
            "command": {{ command }},
            "env": {{ env }},
            "resources": {
              "limits": {
                "cpu": "{{ cpu }}",
                "memory": "{{ memory }}"
              }
            }
          }
        ],
        "serviceAccount": "{{ service_account_name }}",
        "timeout": "{{ timeout }}"
      }
    }
  }
}
Key differences from your current payload: -
job_body.template
exists at the top level (not under
spec
). - Uses
template.template.containers
for the container spec. - Uses
serviceAccount
and
timeout
(duration, e.g., "600s") instead of
serviceAccountName
and
timeoutSeconds
. - Removes Slack link formatting from annotation keys. - Removes quotes around
env
,
labels
, and
command
so they render as dicts/lists. If you still see the same error after this change, please share: - Your versions of
prefect
and
prefect-gcp
- The rendered
job_body
(after templating, with secrets redacted) so we can confirm the final structure and types. Reference: - Prefect GCP worker guide - Workers concepts