Brazil2026ElectionFilter: How X-Algorithm Implements Brazil's 2026 Election Content Moderation
The Brazil2026ElectionFilter removes posts authored, retweeted, quoted, or replied to by accounts reported to the Brazilian Electoral Court for the 2026 election from recommendation results, unless the viewer follows those accounts, ensuring compliance with Electoral Resolution No. 23.610.
The Brazil2026ElectionFilter serves as a critical compliance mechanism within the X-Algorithm recommendation pipeline. Located in the xai-org/x-algorithm repository, this Rust-based component operates within the home-mixer crate to filter candidate posts during feed generation. It balances Brazilian legal requirements with user autonomy by preserving content from followed accounts while removing potentially problematic electoral content from algorithmic recommendations.
Purpose and Legal Compliance
The filter enforces Electoral Resolution No. 23.610, Art. 28 §1º-A, which mandates the removal of specific accounts from algorithmic promotion during electoral periods. This regulation targets accounts that have been formally reported to the Brazilian Electoral Court regarding the 2026 election cycle.
Unlike blanket censorship, the implementation respects user agency through the follower exception rule. The filter only removes content when the viewer does not already follow the author, preserving the ability of users to see content from accounts they have explicitly chosen to follow. This architectural decision reflects the nuanced requirements of Brazilian electoral law while maintaining user choice.
How Brazil2026ElectionFilter Works
The filter implements the generic Filter<ScoredPostsQuery, PostCandidate> trait, allowing seamless integration into the candidate processing pipeline. The implementation follows a four-step validation process:
Static Prohibited User ID Set
At the core of the filter lies BRAZIL_2026_ELECTION_USER_IDS, a LazyLock<FxHashSet<u64>> containing approximately 2,500 user IDs. This static set, defined in home-mixer/filters/brazil_2026_election_filter.rs, derives from the open data set of 2026 election candidates. The FxHashSet provides O(1) lookup performance critical for high-throughput recommendation processing.
Author Exclusion Logic
The is_excluded_author(user_id, followed_user_ids) function determines whether a specific author should be filtered. This function returns true only when two conditions coincide:
- The
user_idexists withinBRAZIL_2026_ELECTION_USER_IDS - The user ID is not present in the viewer's
followed_user_idsvector
This logic enforces the legal requirement while implementing the follow-relationship exemption.
Multi-Relationship Candidate Evaluation
The should_remove(candidate, followed_user_ids) method performs comprehensive relationship checking across four potential vectors of content propagation:
- Direct authorship – The candidate's
author_idis excluded - Retweet origin – The original author of a retweeted post is excluded
- Quote attribution – The author of quoted content is excluded
- Reply ancestry – Any ancestor user in a reply thread is excluded
If any of these conditions evaluates to true, the candidate is marked for removal from the recommendation set.
Pipeline Integration and Partitioning
Within the filter method implementation, the system extracts the viewer's followed_user_ids from the ScoredPostsQuery context. The candidate vector undergoes partitioning into kept and removed collections based on the should_remove evaluation. The method returns a FilterResult structure containing both sets, allowing the pipeline to track moderation decisions for potential logging or analysis.
Code Implementation and Architecture
Direct Filter Usage
When working with the filter outside the standard pipeline, implementers interact with the Filter trait directly:
use home_mixer::filters::brazil_2026_election_filter::Brazil2026ElectionFilter;
use xai_candidate_pipeline::filter::{Filter, FilterResult};
use home_mixer::models::{candidate::PostCandidate, query::ScoredPostsQuery};
// Construct query with viewer's follow relationships
let query = ScoredPostsQuery {
user_features: UserFeatures {
followed_user_ids: vec![12345, 67890],
..Default::default()
},
..Default::default()
};
// Create candidate batch containing mixed authors
let candidates = vec![
PostCandidate { tweet_id: 1, author_id: 1, ..Default::default() }, // Permitted
PostCandidate { tweet_id: 2, author_id: 14160928, ..Default::default() }, // Blocked ID
];
let filter = Brazil2026ElectionFilter;
let result: FilterResult<PostCandidate> = filter.filter(&query, candidates);
// Verify filtering behavior
assert_eq!(result.kept.len(), 1);
assert_eq!(result.removed[0].author_id, 14160928);
Pipeline Registration
The filter integrates into the Phoenix candidate pipeline through explicit registration in phoenix_candidate_pipeline.rs:
use crate::filters::brazil_2026_election_filter::Brazil2026ElectionFilter;
let filters: Vec<Box<dyn Filter<ScoredPostsQuery, PostCandidate>>> = vec![
// Preceding filters...
Box::new(Brazil2026ElectionFilter),
// Subsequent filters...
];
During request processing, the pipeline invokes each filter's filter method sequentially. The Brazil 2026 filter executes early in the chain, ensuring prohibited content never reaches downstream ranking or feature extraction stages.
Key Source Files and Data Structures
Understanding the filter requires familiarity with these specific files in the xai-org/x-algorithm repository:
home-mixer/filters/brazil_2026_election_filter.rs– Contains theBrazil2026ElectionFilterstruct, static ID set, trait implementation, and comprehensive unit testshome-mixer/candidate_pipeline/phoenix_candidate_pipeline.rs– Registers the filter within the candidate processing pipeline at lines 38-41home-mixer/models/candidate.rs– DefinesPostCandidate, the core data structure filtered, including fields for author IDs, retweet sources, and quote referenceshome-mixer/models/query.rs– DefinesScoredPostsQuery, which carries thefollowed_user_idsvector essential for the exemption logic
Summary
- The
Brazil2026ElectionFilterenforces Brazilian Electoral Resolution No. 23.610 by removing specific accounts from algorithmic recommendations during the 2026 election period. - The filter references a static set of approximately 2,500 prohibited user IDs stored in
BRAZIL_2026_ELECTION_USER_IDSwithinhome-mixer/filters/brazil_2026_election_filter.rs. - Content removal only occurs when the viewer does not follow the author, implementing the legal "follower exception" requirement.
- The
should_removemethod checks four relationship types: direct authorship, retweets, quotes, and reply ancestors to ensure comprehensive coverage. - Unit tests verify that the filter maintains non-empty ID sets, correctly handles follow relationships, and properly processes retweet and quote metadata.
Frequently Asked Questions
What specific Brazilian law does the Brazil2026ElectionFilter enforce?
The filter implements Electoral Resolution No. 23.610, Art. 28 §1º-A, which mandates that platforms remove from algorithmic recommendations any content produced by accounts reported to the Superior Electoral Court (TSE) regarding the 2026 elections. The X-Algorithm codebase explicitly references this legal foundation in its documentation and implementation comments.
How does the filter identify which accounts to remove?
The system maintains a static LazyLock<FxHashSet<u64>> named BRAZIL_2026_ELECTION_USER_IDS containing approximately 2,500 blacklisted user IDs. The is_excluded_author function performs O(1) hash set lookups to determine if a user ID requires filtering. This approach ensures minimal latency during the recommendation pipeline's execution while maintaining deterministic behavior based on the official electoral court data set.
Why can users still see content from filtered accounts sometimes?
The implementation respects the follow relationship exception specified in Brazilian electoral law. The should_remove method explicitly checks the viewer's followed_user_ids vector before filtering. If a user follows an account listed in the prohibited set, that account's content remains visible in their recommendations. This architectural decision preserves user autonomy while complying with legal requirements regarding algorithmic amplification of unknown accounts.
Where does the static list of prohibited IDs originate?
The BRAZIL_2026_ELECTION_USER_IDS set derives from the open data set of 2026 election candidates published by Brazilian electoral authorities. According to the source code in home-mixer/filters/brazil_2026_election_filter.rs, this list updates through the standard data pipeline processes and is loaded into memory via LazyLock to prevent repeated disk I/O during high-traffic recommendation requests.
Have a question about this repo?
These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:
curl -s "https://instagit.com/install.md" Maintain an open-source project? Get it listed too →