Home/Tools/@tpmjs/tools-rows-filter

rowsFilterTool

@tpmjs/tools-rows-filter

Filter an array of objects by comparing a field value against a target value. Supports operators: eq (equals), ne (not equals), gt (greater than), lt (less than), gte (greater than or equal), lte (less than or equal), contains (string/array contains). Returns filtered rows with match statistics.

Official
data
v0.2.0
MIT
⚠️

This tool is currently broken

Execution Failed
Runtime error with test parameters
operator must be one of: eq, ne, gt, lt, gte, lte, contains

Last checked: 1/1/2026, 8:18:27 AM

Interactive Playground

Test @tpmjs/tools-rows-filter (rowsFilterTool) with AI-powered execution

0/2000 characters

Installation & Usage

Install this tool and use it with the AI SDK

1. Install the package

npm install @tpmjs/tools-rows-filter
pnpm add @tpmjs/tools-rows-filter
yarn add @tpmjs/tools-rows-filter
bun add @tpmjs/tools-rows-filter
deno add npm:@tpmjs/tools-rows-filter

2. Import the tool

import { rowsFilterTool } from '@tpmjs/tools-rows-filter';

3. Use with AI SDK

import { generateText } from 'ai';
import { openai } from '@ai-sdk/openai';
import { rowsFilterTool } from '@tpmjs/tools-rows-filter';

const result = await generateText({
  model: openai('gpt-4o'),
  tools: { rowsFilterTool },
  prompt: 'Your prompt here...',
});

console.log(result.text);

Parameters

Available configuration options

Auto-extracted
rows
Required
Type: array

Array of objects to filter

field
Required
Type: string

Field name to filter on (supports dot notation for nested fields, e.g., "user.name")

operator
Required
Type: string

Comparison operator to use

value
Required
Type: object

Value to compare against (type should match the field type for numeric/string comparisons)

Schema extracted: 1/1/2026, 8:18:27 AM

README

@tpmjs/tools-rows-filter

Filter an array of objects by comparing field values against target values using various comparison operators.

Features

  • Multiple operators: eq, ne, gt, lt, gte, lte, contains
  • Nested field support: Use dot notation to access nested properties (e.g., user.name)
  • Type-aware comparisons: Handles numbers, strings, and arrays appropriately
  • Case-insensitive contains: String matching is case-insensitive for contains operator
  • Match statistics: Returns count of matches and total rows

Installation

npm install @tpmjs/tools-rows-filter ai

Usage

import { rowsFilterTool } from '@tpmjs/tools-rows-filter';
import { generateText } from 'ai';

const result = await generateText({
  model: yourModel,
  tools: {
    rowsFilter: rowsFilterTool,
  },
  prompt: 'Filter the users to show only those over 25 years old',
});

Parameters

  • rows (array, required): Array of objects to filter
  • field (string, required): Field name to filter on (supports dot notation)
  • operator (string, required): Comparison operator to use
    • eq: equals
    • ne: not equals
    • gt: greater than (numbers/strings)
    • lt: less than (numbers/strings)
    • gte: greater than or equal (numbers/strings)
    • lte: less than or equal (numbers/strings)
    • contains: substring match (case-insensitive) or array contains
  • value (any, required): Value to compare against

Returns

{
  rows: Record<string, unknown>[],  // Filtered array
  matchCount: number,                // Number of matching rows
  totalCount: number                 // Total number of input rows
}

Examples

Filter by numeric comparison

const data = [
  { name: 'Alice', age: 30 },
  { name: 'Bob', age: 25 },
  { name: 'Charlie', age: 35 },
];

// Returns: { rows: [Alice, Charlie], matchCount: 2, totalCount: 3 }
await rowsFilterTool.execute({
  rows: data,
  field: 'age',
  operator: 'gte',
  value: 30,
});

Filter by string equality

const products = [
  { name: 'Laptop', category: 'electronics' },
  { name: 'Desk', category: 'furniture' },
  { name: 'Phone', category: 'electronics' },
];

// Returns: { rows: [Laptop, Phone], matchCount: 2, totalCount: 3 }
await rowsFilterTool.execute({
  rows: products,
  field: 'category',
  operator: 'eq',
  value: 'electronics',
});

Filter by substring contains

const users = [
  { email: 'alice@example.com' },
  { email: 'bob@gmail.com' },
  { email: 'charlie@example.com' },
];

// Returns: { rows: [alice, charlie], matchCount: 2, totalCount: 3 }
await rowsFilterTool.execute({
  rows: users,
  field: 'email',
  operator: 'contains',
  value: 'example',
});

Filter by nested field

const orders = [
  { id: 1, customer: { name: 'Alice', tier: 'premium' } },
  { id: 2, customer: { name: 'Bob', tier: 'basic' } },
  { id: 3, customer: { name: 'Charlie', tier: 'premium' } },
];

// Returns: { rows: [order1, order3], matchCount: 2, totalCount: 3 }
await rowsFilterTool.execute({
  rows: orders,
  field: 'customer.tier',
  operator: 'eq',
  value: 'premium',
});

License

MIT

Statistics

Downloads/month

41

Quality Score

78%

Bundle Size

NPM Keywords

tpmjs
data
filter
array

Maintainers

thomasdavis(thomasalwyndavis@gmail.com)

Frameworks

vercel-ai