Skip to content

feat: add descriptive error for ACS 1-year population threshold#145

Open
vijaygovindaraja wants to merge 2 commits intouscensusbureau:mainfrom
vijaygovindaraja:feat/35-acs-1year-population-threshold
Open

feat: add descriptive error for ACS 1-year population threshold#145
vijaygovindaraja wants to merge 2 commits intouscensusbureau:mainfrom
vijaygovindaraja:feat/35-acs-1year-population-threshold

Conversation

@vijaygovindaraja
Copy link
Copy Markdown

Summary

ACS 1-year estimates are only available for geographic areas with populations of 65,000+. When users query smaller areas, the Census API returns a generic 400 error with no explanation — a common source of confusion.

This PR adds two improvements following the approach discussed by @luke-keller-census and @annav-gov:

1. Proactive guidance in tool description

Added a note to the fetch-aggregate-data tool description warning about the ACS 1-year population threshold and suggesting 5-year data as an alternative. This helps LLM agents avoid the error entirely.

2. Descriptive error message on 400

When a 400 error is returned for an ACS 1-year dataset, the error message now explains:

  • The 65,000 population threshold
  • Suggests using acs/acs5 instead
  • Links to the Census Bureau guidance page

Before:

Census API error: 400 Bad Request

After:

Census API error: 400 Bad Request. Note: ACS 1-year estimates (acs/acs1) are only
available for geographic areas with populations of 65,000 or more. If the requested
area has a smaller population, try using ACS 5-year estimates instead by changing the
dataset to "acs/acs5". See: https://www.census.gov/programs-surveys/acs/guidance/estimates.html

Fixes #35

Add a content-flattener utility that reduces token usage in MCP tool
responses by:

- Minifying JSON output (removing pretty-print whitespace from
  JSON.stringify calls that used `null, 2` formatting)
- Stripping fields not useful for LLM reasoning (created_at,
  updated_at, parent_geography_level_id)
- Filtering null values from response objects
- Supporting result set truncation with count summaries

Replace all 3 instances of `JSON.stringify(data, null, 2)` in tool
responses with the new `flattenResponse()` helper:
- search-data-tables.tool.ts
- fetch-dataset-geography.tool.ts
- resolve-geography-fips.tool.ts

For a typical 100-item geography response, this reduces token usage
by ~30-40% by eliminating indentation whitespace and null fields.

Fixes uscensusbureau#70

Signed-off-by: V Govindarajan <vijay.govindarajan91@gmail.com>
ACS 1-year estimates are only available for areas with populations
of 65,000+. When users query smaller areas, the Census API returns
a generic 400 error with no explanation. This is a common source of
confusion for data users.

Two changes:
1. Update the tool description to proactively warn about the ACS
   1-year population threshold, guiding LLM agents to suggest
   5-year data for smaller geographies
2. When a 400 error is returned for an ACS 1-year dataset, provide
   a descriptive error message explaining the population threshold
   and suggesting ACS 5-year as an alternative

This follows the approach discussed by @luke-keller-census and
@annav-gov in the issue thread.

Fixes uscensusbureau#35

Signed-off-by: V Govindarajan <vijay.govindarajan91@gmail.com>
@vijaygovindaraja
Copy link
Copy Markdown
Author

@luke-keller-census checking in on this one — adds descriptive errors for ACS 1-year population thresholds.

@vijaygovindaraja
Copy link
Copy Markdown
Author

@luke-keller-census @curt-mitch-gov would you be able to take a look at this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Return a descriptive error if a user requests ACS 1-year data for a place with less than 65,000 people

1 participant