Skip to main content
Glama

analyze_sentiment

Analyze text sentiment using FinBERT to determine polarity, confidence, and classification for news headlines or articles in quantitative finance contexts.

Instructions

Analyzes the sentiment of a given text using FinBERT on Modal (via Public Endpoint).

Args:
    text: Text to analyze (e.g., news headline, article).

Returns:
    Dictionary with polarity, confidence, and classification.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
textYes

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The core handler function that analyzes sentiment of input text using FinBERT model via Modal endpoint. Posts text to MODAL_ENDPOINT_URL, processes response to polarity and classification.
    def analyze_sentiment(text: str) -> Dict[str, Any]:
        """
        Analyzes the sentiment of a given text using FinBERT on Modal (via Public Endpoint).
        
        Args:
            text: Text to analyze (e.g., news headline, article).
        
        Returns:
            Dictionary with polarity, confidence, and classification.
        """
        # Try Modal first
        try:
            # Check if URL is configured
            if "replace-me" in MODAL_ENDPOINT_URL:
                raise ValueError("Modal URL not configured")
    
            response = requests.post(MODAL_ENDPOINT_URL, json={"text": text}, timeout=15)
            response.raise_for_status()
            result = response.json()
            
            # FinBERT returns {'label': 'positive'/'negative'/'neutral', 'score': float}
            label = result['label'].upper()
            score = result['score']
            
            # Map to polarity-like score for compatibility (-1 to 1)
            if label == "POSITIVE":
                polarity = score
            elif label == "NEGATIVE":
                polarity = -score
            else:
                polarity = 0.0
                
            return {
                "text": text[:100] + "..." if len(text) > 100 else text,
                "polarity": round(polarity, 3),
                "subjectivity": 0.0, # FinBERT doesn't give subjectivity
                "classification": label,
                "model": "FinBERT (Modal Public)"
            }
            
        except Exception as e:
            logger.error(f"Modal FinBERT failed: {e}")
            return {"error": f"Error analyzing sentiment: {str(e)}"}
  • server.py:405-408 (registration)
    Registers the analyze_sentiment tool (along with related news tools) with the MCP server using the register_tools helper function.
    register_tools(
        [get_news, analyze_sentiment, get_symbol_sentiment],
        "News & Sentiment"
    )
  • app.py:293-293 (registration)
    Includes analyze_sentiment in the tools_map dictionary under 'News & Sentiment' category, used for Gradio UI toolbox and potentially MCP exposure via Gradio's mcp_server=True.
    "News & Sentiment": [get_news, analyze_sentiment, get_symbol_sentiment, get_news_resource],
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries the full burden. It mentions the implementation ('FinBERT on Modal via Public Endpoint'), which adds some context, but lacks critical behavioral details: it doesn't disclose rate limits, authentication needs, error handling, or what 'polarity, confidence, and classification' entail. For a tool with no annotations, this is insufficient.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is well-structured and concise. It uses three sentences: one for the purpose, one for the parameter, and one for the return value. Each sentence adds value without redundancy, and the information is front-loaded with the core functionality.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's complexity (sentiment analysis with 1 parameter), no annotations, and an output schema (implied by 'Returns'), the description is moderately complete. It covers purpose, parameter semantics, and return structure, but lacks behavioral context like rate limits or error handling. The output schema likely details the return dictionary, so the description doesn't need to explain return values further.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The description adds meaningful semantics beyond the input schema. The schema has 0% description coverage and only defines 'text' as a string. The description clarifies the parameter's purpose ('Text to analyze') and provides an example ('e.g., news headline, article'), which compensates for the low schema coverage. With 1 parameter, this is adequate.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose: 'Analyzes the sentiment of a given text using FinBERT on Modal (via Public Endpoint).' It specifies the verb ('analyzes'), resource ('sentiment'), and implementation details. However, it doesn't explicitly differentiate from sibling tools like 'get_symbol_sentiment', which appears to be a related sentiment analysis tool.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides minimal usage guidance. It includes an example ('e.g., news headline, article') but doesn't specify when to use this tool versus alternatives like 'get_symbol_sentiment' or other text-processing tools. There's no explicit context, exclusions, or prerequisites mentioned.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/N-lia/MonteWalk'

If you have feedback or need assistance with the MCP directory API, please join our Discord server