Skip to main content
The --extract flag returns strictly-typed JSON output instead of natural language. Five built-in schemas cover common intelligence extraction patterns.
Model OverrideUsing --extract automatically selects the grok-4-1-fast-non-reasoning model, regardless of --fast or --deep flags. This is required by the xAI Responses API for structured output with tools.

Schema Types

Sentiment Analysis

Extract overall sentiment, sentiment scoring, key claims, and notable accounts discussing a topic.Use cases:
  • Market sentiment tracking (crypto, stocks, commodities)
  • Brand perception monitoring
  • Political opinion analysis
  • Community mood detection

Schema Definition

topic
string
required
The topic being analyzed
timeframe
string
required
The time period covered by the analysis
overall_sentiment
string
required
Natural language description of the dominant sentiment (e.g., “cautiously bullish”, “strongly negative”, “mixed with bearish tilt”)
sentiment_score
number
required
Numeric sentiment score from -1.0 (very bearish/negative) to 1.0 (very bullish/positive)
key_claims
array
required
Array of significant claims being made about the topic
notable_accounts
array
required
Array of X handles (strings) that are significant voices in the conversation
visual_content_summary
string
required
Summary of visual content found in posts (if --images or --videos was used)
summary
string
required
High-level summary of the sentiment analysis findings

Example Output

{
  "topic": "Bitcoin",
  "timeframe": "Last 24 hours",
  "overall_sentiment": "cautiously bullish",
  "sentiment_score": 0.41,
  "key_claims": [
    {
      "claim": "The ETF inflow numbers suggest institutional accumulation is quietly accelerating despite retail uncertainty.",
      "handle": "woonomic",
      "sentiment": "bullish",
      "url": "https://x.com/woonomic/status/..."
    },
    {
      "claim": "The halving is already priced in. Anyone expecting a 2020-style run is going to be disappointed.",
      "handle": "PeterLBrandt",
      "sentiment": "skeptical",
      "url": "https://x.com/PeterLBrandt/status/..."
    }
  ],
  "notable_accounts": ["woonomic", "PeterLBrandt", "saylor", "PrestonPysh"],
  "visual_content_summary": "Multiple charts showing ETF inflows and on-chain metrics. Price action screenshots from trading platforms.",
  "summary": "Bitcoin sentiment is cautiously bullish with a score of 0.41. Institutional accumulation narrative is strong, but macro headwinds and halving skepticism provide counterbalance."
}

Command Example

/grok-x "Bitcoin sentiment on X right now" --extract sentiment
/grok-x "Tesla brand perception" --extract sentiment --from 2026-02-01
/grok-x "AI safety discourse" --extract sentiment --handles ylecun,sama

Schema Constraints

Strict Schema EnforcementAll schemas use strict: true mode with additionalProperties: false. Grok is forced to return JSON that exactly matches the schema — no extra fields, no missing required fields.If Grok cannot extract enough information to populate required fields, it will return minimal valid JSON rather than failing.

Technical Implementation

When you use --extract, the following happens:
  1. Model override: Model is forced to grok-4-1-fast-non-reasoning (required for structured output with tools)
  2. Streaming disabled: Structured output is non-streaming by design
  3. Schema injection: The schema is passed to the Responses API as:
    "text": {
      "format": {
        "type": "json_schema",
        "name": "<schema_name>",
        "schema": SCHEMAS[schema_name],
        "strict": True
      }
    }
    
  4. JSON parsing: Response is parsed as JSON and printed with indentation
  5. Validation: The xAI API validates the output against the schema before returning it
See grok_x.py:289-308 for implementation details.

Combining with Other Flags

Valid Combinations

# Extraction + handle filtering
/grok-x "query" --extract sentiment --handles saylor,jack

# Extraction + date range
/grok-x "query" --extract timeline --from 2026-01-01 --to 2026-03-01

# Extraction + media analysis
/grok-x "query" --extract narrative --images --videos

# Extraction + web search
/grok-x "query" --extract claims --web

Invalid Combinations

--extract cannot be combined with --analyzeThese are mutually exclusive capabilities. Choose either:
  • Quantitative analysis (--analyze for code interpreter)
  • Structured extraction (--extract SCHEMA for typed JSON)
This is an xAI API limitation.

Raw Schema Access

The schemas are defined in grok_x.py lines 22-150 as the SCHEMAS dictionary. You can inspect them directly:
SCHEMAS = {
    "sentiment": { ... },
    "narrative": { ... },
    "timeline": { ... },
    "profiles": { ... },
    "claims": { ... }
}
Each schema is a JSON Schema object with:
  • type: "object"
  • properties: Field definitions with types and descriptions
  • required: List of mandatory fields
  • additionalProperties: false: No extra fields allowed

Build docs developers (and LLMs) love