Strict-JSON Agent¶
Overview¶
The Strict-JSON agent is a testing variant of the strict-referenced agent designed to compare the effects of prompt-based JSON formatting vs API-enforced JSON mode.
Purpose¶
This agent helps answer the question: Does enforcing JSON mode at the API level (rather than just prompting for JSON) produce more natural, less structured responses?
The hypothesis is that using OpenAI's response_format: {"type": "json_object"} parameter might prevent the LLM from falling into "ChatGPT mode" with overly structured responses containing headers like "Scoped question:", "Short answer:", etc.
Implementation Details¶
Same Prompt as Strict-Referenced¶
The agent uses the identical system prompt as strict-referenced:
- Cannot use its own knowledge - everything must be confirmed through research tools
- Every piece of information must be directly sourced from search results
- Must include references for every claim
- Search thoroughly before responding
- Refuses to answer if insufficient reliable sources are found
Key Difference: JSON Mode Enforcement¶
Unlike strict-referenced which only prompts for JSON format in text, strict-json enforces it at the API level:
This uses OpenAI's native JSON mode which guarantees valid JSON output and may influence the model's behavior.
Usage¶
API Endpoint¶
Request Format¶
Same as other agents:
{
"messages": [
{"role": "user", "content": "Your medical question here"}
],
"profile": "Name: ...\nLocation: ...\nLanguage: ...",
"tools": ["search_nihai", "ask_nihai"],
"model": "gpt-4o",
"reasoning": true
}
Response Format¶
Standard AshaiResponse:
Testing in UI¶
- Go to
/agentspage - Select
/agent/strict-jsonfrom dropdown - Use the default example or enter your own query
- Compare responses with
/agent/strict-referenced
Expected Behavior¶
Tool Requirements¶
- Requires at least one tool - will refuse to answer if
tools: []ortools: ["none"] - Default tools:
search_nihai,ask_nihai
Reference Requirements¶
- Must return references - will return error message if no references found after search
- References are validated and enforced
Research Indication¶
The thinking field will include: "Performed research using available tools (september, pubmed, googlesheet, perplexity) with JSON mode enforcement."
Comparison Testing¶
To test the hypothesis about JSON mode effects on response naturalness:
- Run the same query on both agents:
/agent/strict-referenced(prompt-based JSON)-
/agent/strict-json(API-enforced JSON) -
Compare:
- Does
strict-jsonproduce fewer structured headers? - Are responses more conversational?
-
Is the content quality similar?
-
Use in evaluations:
- Add
strict-jsonto evaluation batches - Compare scores across metrics
- Analyze response patterns
Technical Notes¶
Code Location¶
- Agent:
agents/strict_json/strict_json.py - Route:
agents/routes.py(line 452) - UI Integration:
templates/agents_page.html
Modified Components¶
agents/agent.py: Addeduse_json_modeparameter torun_generic_agent()agents/strict_json/: New agent moduleagents/routes.py: New/strict-jsonendpointtemplates/agents_page.html: UI integration for agent selection and configuration
Future Improvements¶
- [ ] A/B test with real users to gather qualitative feedback
- [ ] Automated evaluation comparing response naturalness
- [ ] Track whether JSON mode affects tool calling behavior
- [ ] Consider making JSON mode a configurable parameter for all agents
Related Agents¶
- strict-referenced: Same requirements, prompt-based JSON
- strict-referenced-after: Answer-first-verify approach
- ashai: General medical AI without strict referencing requirements