influxdata/influxdb · error · InvalidLineError

At least one field is required

Error message

At least one field is required: {line}

What it means

InfluxDB line protocol requires at least one field on every line; tags alone are not a valid data point. build() checks the accumulated fields and raises InvalidLineError if none were added. This is a builder-state validation, not a per-call check, so it surfaces only at build time.

Solutions

  1. Ensure at least one field is added before build(), e.g. always call string_field/float64_field with a default value.
  2. Check `if not builder.fields: ...` or track field count before calling build().
  3. Fix the upstream logic that skipped field population (e.g. missing column, failed parse).

Example fix

// before
builder.measurement("cpu").tag("host", "a")
line = builder.build()  # raises
// after
builder.measurement("cpu").tag("host", "a").float64_field("usage", 0.0)
line = builder.build()
Defensive patterns

Strategy: validation

Validate before calling

if not builder.fields:
    builder.float64_field('value', 0.0)  # or skip the point entirely

Try / catch

try:
    line = builder.build()
except InvalidLineError:
    logger.warning('skipping point with no fields')
    line = None

Prevention

When it happens

Trigger: Creating LineBuilder, adding only tag() calls (or none at all), then calling build(); conditionally adding fields with all conditions false.

Common situations: Code paths where field extraction fails silently and no fields are added; templated ingestion where a schema maps columns to fields but the column list is empty; users assuming tags alone form a valid point.

Understand the failure class

Background: "must not be empty", "cannot be empty" — required-field validation errors across open-source libraries — this error's family across 41 libraries.

Related errors


AI-assisted analysis of influxdata/influxdb@06200ef96b (2026-09-19). Data as JSON: /api/errors/5f7b7922d2ee36c8. Report an issue: GitHub.

Appendix: source

Thrown at influxdb3_py_api/src/line_builder/line_builder.py:132

        self._timestamp_ns = timestamp_ns
        return self

    def build(self) -> str:
        """Build the line protocol string."""
        # Start with measurement name (escape commas and spaces)
        line = self._escape_measurement(self.measurement)

        # Add tags if present
        if self.tags:
            tags_str = ",".join(
                f"{key}={self._escape_tag_value(value)}"
                for key, value in self.tags.items()
            )
            line += f",{tags_str}"

        # Add fields (required)
        if not self.fields:
            raise InvalidLineError(f"At least one field is required: {line}")

        fields_str = ",".join(
            f"{self._escape_field_key(key)}={value}"
            for key, value in self.fields.items()
        )
        line += f" {fields_str}"

        # Add timestamp if present
        if self._timestamp_ns is not None:
            line += f" {self._timestamp_ns}"

        return line

View on GitHub (pinned to 06200ef96b)