Skip to content

Commit 25b64a4

Browse files
committed
Fix filter parameter validation issue
- Fix schema inconsistency: change 'filters' (object) to 'filter' (string) - Update tool schema to use proper OData string format - Update README documentation to match corrected schema - Add demo script showing old vs new format Resolves filter validation error: Before: {"filters": {"data_source": {"eq": "GAO"}}} After: {"filter": "data_source eq 'GAO'"} This fixes the "Filter validation failed" error users were encountering.
1 parent 0d3e507 commit 25b64a4

File tree

3 files changed

+56
-9
lines changed

3 files changed

+56
-9
lines changed

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -126,13 +126,13 @@ For Docker:
126126
The server provides two main tools:
127127

128128
### 1. PIA Search
129-
Comprehensive search with OData filtering and faceting. The `filters` parameter uses standard [OData query syntax](https://docs.oasis-open.org/odata/odata/v4.01/odata-v4.01-part2-url-conventions.html).
129+
Comprehensive search with OData filtering and faceting. The `filter` parameter uses standard [OData query syntax](https://docs.oasis-open.org/odata/odata/v4.01/odata-v4.01-part2-url-conventions.html).
130130

131131
**Tool Name:** `pia_search`
132132

133133
**Parameters:**
134134
- `query` (required): Search query text
135-
- `filters` (optional): OData filter expression
135+
- `filter` (optional): OData filter expression
136136
- `page` (optional): Page number (default: 1)
137137
- `page_size` (optional): Results per page (default: 10)
138138
- `search_mode` (optional): Search mode (default: "content")
@@ -181,7 +181,7 @@ Discover available field names and values for filtering.
181181
- Find possible field values (e.g., "OIG", "GAO", "audit_report")
182182
- Understand data types for each field (string, date, number)
183183

184-
This information helps you construct proper `filters` for the `pia_search` tool.
184+
This information helps you construct proper `filter` expressions for the `pia_search` tool.
185185

186186
## 🔍 Filter Discovery Workflow
187187

@@ -207,13 +207,13 @@ Use the `pia_search` tool with discovered fields to create precise OData filters
207207
**Basic Example:**
208208
```
209209
Query: "Medicare fraud"
210-
Filters: "data_source in ('OIG', 'CMS') and published_date ge '2023-01-01' and document_type eq 'audit_report'"
210+
Filter: "data_source in ('OIG', 'CMS') and published_date ge '2023-01-01' and document_type eq 'audit_report'"
211211
```
212212

213213
**Complex Example:**
214214
```
215215
Query: "healthcare violations"
216-
Filters: "(data_source eq 'OIG' or data_source eq 'CMS') and (severity eq 'High' or amount gt 1000000) and published_date ge '2023-01-01'"
216+
Filter: "(data_source eq 'OIG' or data_source eq 'CMS') and (severity eq 'High' or amount gt 1000000) and published_date ge '2023-01-01'"
217217
```
218218

219219
## 📝 AI Instruction Prompts

filter_fix_demo.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#!/usr/bin/env python3
2+
"""
3+
Demo script showing the correct filter format after the fix.
4+
5+
BEFORE (caused error):
6+
{
7+
"limit": 15,
8+
"query": "ambulance fraud Medicare Medicaid emergency medical transportation",
9+
"filters": {
10+
"data_source": {
11+
"eq": "GAO"
12+
}
13+
}
14+
}
15+
16+
AFTER (correct format):
17+
{
18+
"limit": 15,
19+
"query": "ambulance fraud Medicare Medicaid emergency medical transportation",
20+
"filter": "data_source eq 'GAO'"
21+
}
22+
"""
23+
24+
import json
25+
26+
# The problematic query that was causing the error
27+
old_format = {
28+
"limit": 15,
29+
"query": "ambulance fraud Medicare Medicaid emergency medical transportation",
30+
"filters": {"data_source": {"eq": "GAO"}},
31+
}
32+
33+
# The correct format after our fix
34+
new_format = {
35+
"limit": 15,
36+
"query": "ambulance fraud Medicare Medicaid emergency medical transportation",
37+
"filter": "data_source eq 'GAO'",
38+
}
39+
40+
print("❌ OLD FORMAT (caused Filter validation failed error):")
41+
print(json.dumps(old_format, indent=2))
42+
print("\n✅ NEW FORMAT (correct OData syntax):")
43+
print(json.dumps(new_format, indent=2))
44+
print("\n🔧 What changed:")
45+
print("1. Parameter name: 'filters' → 'filter'")
46+
print("2. Format: object with nested structure → OData string")
47+
print('3. Value: {"data_source": {"eq": "GAO"}} → "data_source eq \'GAO\'"')

src/pia_mcp_server/tools/search_tools.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@
1313
# Tool definitions based on the API response
1414
pia_search_tool = types.Tool(
1515
name="pia_search",
16-
description="Search the Program Integrity Alliance (PIA) database for documents and recommendations. Returns comprehensive results with full citation information and clickable links for proper attribution. Each result includes corresponding citations with data source attribution (GAO, OIG, etc.). Supports structured filtering using index field names with operators like eq, ne, in, not_in, gte, lte, etc.",
16+
description="Search the Program Integrity Alliance (PIA) database for documents and recommendations. Returns comprehensive results with full citation information and clickable links for proper attribution. Each result includes corresponding citations with data source attribution (GAO, OIG, etc.). Supports OData filter expressions using operators like eq, ne, gt, ge, lt, le, and, or, etc.",
1717
inputSchema={
1818
"type": "object",
1919
"properties": {
2020
"query": {"type": "string", "description": "Search query text"},
21-
"filters": {
22-
"type": "object",
23-
"description": "Optional filters for narrowing results",
21+
"filter": {
22+
"type": "string",
23+
"description": "Optional OData filter expression for narrowing results (e.g., \"data_source eq 'GAO'\")",
2424
},
2525
"page": {
2626
"type": "integer",

0 commit comments

Comments
 (0)