googleapis/mcp-toolbox · error

failed to parse data quality spec JSON: %w

Error message

failed to parse data quality spec JSON: %w

What it means

GenerateDataQuality accepts a caller-supplied DataQualitySpec as JSON and decodes it with protojson into a DataQualitySpec proto before creating a DataScan. If the JSON is not valid JSON or does not match the DataQualitySpec schema (wrong field names, wrong types, non-camelCase keys without protojson options), the parse fails with this wrapped error.

Source

Thrown at internal/sources/dataplex/dataplex.go:1048

				"onemcp-server": "true",
			},
		},
	}

	op, err := s.DataScanClient.CreateDataScan(ctx, req)
	if err != nil {
		return "", err
	}
	return op.Name(), nil
}

func (s *Source) GenerateDataQuality(ctx context.Context, location, resourcePath string, specJSON string, publish bool) (string, error) {
	parent := fmt.Sprintf("projects/%s/locations/%s", s.ProjectID(), location)
	dataScanID := fmt.Sprintf("nq-dq-%s", uuid.New().String())

	var dqSpec dataplexpb.DataQualitySpec
	if err := protojson.Unmarshal([]byte(specJSON), &dqSpec); err != nil {
		return "", fmt.Errorf("failed to parse data quality spec JSON: %w", err)
	}
	dqSpec.CatalogPublishingEnabled = publish

	req := &dataplexpb.CreateDataScanRequest{
		Parent:     parent,
		DataScanId: dataScanID,
		DataScan: &dataplexpb.DataScan{
			Data: &dataplexpb.DataSource{
				Source: &dataplexpb.DataSource_Resource{
					Resource: resourcePath,
				},
			},
			Spec: &dataplexpb.DataScan_DataQualitySpec{
				DataQualitySpec: &dqSpec,
			},
			ExecutionSpec: &dataplexpb.DataScan_ExecutionSpec{
				Trigger: &dataplexpb.Trigger{
					Mode: &dataplexpb.Trigger_OneTime_{

View on GitHub (pinned to 8cc6e09de2)

Solutions

  1. Validate specJSON with a JSON linter and against the DataQualitySpec proto schema
  2. Use camelCase field names (protojson convention) e.g. rowCondition not row_condition
  3. Remove unknown fields — protojson.Unmarshal rejects them by default; or parse with protojson.UnmarshalOptions{DiscardUnknown: true} in a fork/patch
  4. Start from a minimal known-good spec (e.g. {"rules":[]}) and add fields incrementally

Example fix

// before
spec := `{"rules": [{"row_condition": "col > 0", "suspicious_threshold": 0.5}]}`
// after
spec := `{"rules": [{"rowCondition": "col > 0", "suspiciousThreshold": 0.5}]}`
Defensive patterns

Strategy: validation

Validate before calling

var probe map[string]any
if err := json.Unmarshal([]byte(specJSON), &probe); err != nil {
	return fmt.Errorf("invalid spec JSON: %w", err)
}
if _, ok := probe["rules"]; !ok { return errors.New("spec missing 'rules' field") }

Try / catch

id, err := src.GenerateDataQuality(ctx, loc, res, spec, true)
if err != nil {
	if strings.Contains(err.Error(), "failed to parse data quality spec JSON") {
		return fmt.Errorf("fix spec JSON (camelCase keys, no unknown fields): %w", err)
	}
	return err
}

Prevention

When it happens

Trigger: Calling GenerateDataQuality with specJSON containing malformed JSON, unknown fields (protojson rejects unknown fields by default), snake_case keys instead of camelCase, or wrong value types (e.g. string where a number is required).

Common situations: Hand-authoring the spec with snake_case field names; copying a spec from a different proto version; trailing commas or comments in the JSON; embedding rules with invalid rowCondition expressions at the JSON type level.

Understand the failure class

Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.

Related errors


AI-assisted analysis of googleapis/mcp-toolbox@8cc6e09de2 (2026-09-05). Data as JSON: /api/errors/0dad0b6935097b48. Report an issue: GitHub.